K
kceiw
How to make a member function inline while the declaration and
implementation are separated?
implementation are separated?
kceiw said:How to make a member function inline while the declaration and
implementation are separated?
Squeamizh said:If you want to keep the declaration and body separate, then the easiest
way to do it is by puttin the function body in the same header file as
the class definition, but outside the actual class.
E.G.:
--- BEGIN EXAMPLE.H ----
class Example {
public:
Example();
inline void helloWorld() const;
};
void Example::helloWorld() const {
std::cout << "hello world";
}
--- END EXAMPLE.H ---
Your example wouldn't result in the member function being declared
inline, as the OP specified. I think perhaps you meant something like:
class Example {
public:
void memFunc() const;
};
inline void Example::memFunc() const
{
doSomething();
}
Best regards,
Tom
How about when the inline function are put outside the header file? When
I try to do it, it make an error while linking.
Do I have to put the function body in the header file when I want to
make it inline? Dose it differ when I define the function while it's
declared?
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.