By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,713 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,713 IT Pros & Developers. It's quick & easy.

inline functions provide macro functionality?

P: n/a
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,



Jun 27 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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-lit...functions.html

--
rbh
Jun 27 '07 #2

P: n/a
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-lit...functions.html

--
rbh
Thank you...

Jun 28 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.