inline functions provide macro functionality?



 DEVELOP > c-Plus-Plus > inline functions provide macro functionality?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "aaragon"
Date: 27 Jun 2007 06:01:17 PM
Object: inline functions provide macro functionality?
Hi everyone,
I would like to create a very simple function:
// header file
inline void point_map() {
PointMap pointMap =3D get(vertex_point_t(), g);
}
// main.cpp
point_map();
pointMap[0] =3D Point(2.1,5.4); // error, pointMap variable was
not declared
The function definition is not important, I'm using the BOOST graph
library for working with Graph data structures. The important thing is
that I would like the compiler to replace the body of the code shown
above so I can use pointMap later on. This could be done easily by the
preprocessor with a macro (which I don't want to use), but I thought
that the inline statement provided kind of the same functionality
because an inline function just replaces the body of that function.
However, as with regular functions, I have a compiler message saying
that the pointMap variable was not declared in that scope (therefore
showing that no function body was replaced). I'm new to inline
functions, am I misunderstanding the concept of inline functions?
Thank you,
a=B2
.

User: "Robert Bauck Hamar"

Title: Re: inline functions provide macro functionality? 27 Jun 2007 06:17:20 PM
aaragon wrote:

Hi everyone,

I would like to create a very simple function:

// header file
inline void point_map() {
PointMap pointMap = get(vertex_point_t(), g);
}

// main.cpp

point_map();
pointMap[0] = Point(2.1,5.4); // error, pointMap variable was
not declared

The function definition is not important, I'm using the BOOST graph
library for working with Graph data structures. The important thing is
that I would like the compiler to replace the body of the code shown
above so I can use pointMap later on. This could be done easily by the
preprocessor with a macro (which I don't want to use), but I thought
that the inline statement provided kind of the same functionality
because an inline function just replaces the body of that function.

No, an inline function is just an ordinary function. The only thing that
makes inline functions different from other functions, is that they can be
defined in multiple translation units (or in english: you put the body in a
header file.)
The keyword inline doesn't mean that the function will actually be inlined,
as the absence of it doesn't mean that the function will not be inlined.
The compiler does as it pleases. (And there exist compilers that can
actually inline functions that are compiled in other translation units.)

However, as with regular functions, I have a compiler message saying
that the pointMap variable was not declared in that scope (therefore
showing that no function body was replaced). I'm new to inline
functions, am I misunderstanding the concept of inline functions?

Yes, you are misunderstanding.
http://www.parashift.com/c++-faq-lite/inline-functions.html
--
rbh
.
User: "aaragon"

Title: Re: inline functions provide macro functionality? 28 Jun 2007 01:30:22 AM
On Jun 27, 6:17 pm, Robert Bauck Hamar <roberth+n...@ifi.uio.no>
wrote:

aaragon wrote:

Hi everyone,


I would like to create a very simple function:


// header file
inline void point_map() {
PointMap pointMap = get(vertex_point_t(), g);
}


// main.cpp


point_map();
pointMap[0] = Point(2.1,5.4); // error, pointMap variable was
not declared


The function definition is not important, I'm using the BOOST graph
library for working with Graph data structures. The important thing is
that I would like the compiler to replace the body of the code shown
above so I can use pointMap later on. This could be done easily by the
preprocessor with a macro (which I don't want to use), but I thought
that the inline statement provided kind of the same functionality
because an inline function just replaces the body of that function.


No, an inline function is just an ordinary function. The only thing that
makes inline functions different from other functions, is that they can be
defined in multiple translation units (or in english: you put the body in a
header file.)

The keyword inline doesn't mean that the function will actually be inlined,
as the absence of it doesn't mean that the function will not be inlined.
The compiler does as it pleases. (And there exist compilers that can
actually inline functions that are compiled in other translation units.)

However, as with regular functions, I have a compiler message saying
that the pointMap variable was not declared in that scope (therefore
showing that no function body was replaced). I'm new to inline
functions, am I misunderstanding the concept of inline functions?


Yes, you are misunderstanding.

http://www.parashift.com/c++-faq-lite/inline-functions.html

--
rbh

Thank you...
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER