Option 1:
//A.h
class A
{
void foo()
{
}
};
Option 2:
//A.h
class A
{
void foo();
};
inline void A::foo()
{
}
Note that in option 2, the method is also implemented in the header (marked inline to prevent multiple definition).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A method defined inside the class definition is implicitly
inline, so, functionally, there is no difference.Rob provides a good reason on one difference. Here’s another, IMO.
Say you have:
Tell me, is there a way to get notified when the database is disconnected?
Now, try again with:
Easier, right?