inline functions provide macro functionality?

A

aaragon

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.
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,

 
R

Robert Bauck Hamar

aaragon said:
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
 
A

aaragon

aaragon said:
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

Thank you...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top