This makes no sense?

In my book:

"Clicking on Finish will create the skeleton for the function definition within the class definition. If you had not checked Inline, the prototype would appear in the class definition and a function skeleton would be added to the Box.cpp file. You must still edit the declaration in the CBox class definition to make the function const and to add the implementation to the function body."

If I inline was checked should it appear in the Class Declaration, not the definition?

Btw checked means that it was checked in the Visual Studio Member Function Wizard.

Also if the prototype is in the class declaration but the the body is in the definition, it is not automatically inline right?
Last edited on
Also if the prototype is in the class declaration but the the body is in the definition, it is not automatically inline right?


No. An inline function is a hint to the compiler that it should include the complete definition of the function within the header space of the program memory location. If you declare a function as inline and define within the same block then redefine it you will get a linker error saying that the function x is ambiguous.
I know that, but all functions inside a class are inline by default, so if I put the prototype in the class declaration (the header) but the definition in another header, will that work?
I'm not sure why you would want to do this. Ive never done that. Without trying it I'm going to say no. Not within a separate class block.

Try it.
Ok I will but how will I know if it is inline or not?
If I inline was checked should it appear in the Class Declaration, not the definition?


Ignoring the fact that a definition is also a declaration, you cannot include the definition of a function in something that is solely a declaration.

1
2
3
4
5
6
7
8
9
10
11
 // A.h

class A;  // declaration.
class A   // definition.
{
    void someFunc() { /* ... */ }   //implicitly inline.
    void otherFunc() ;
};

// explicitly inlined
inline void A::otherFunc() { /* ... */ }


Definitions of member functions which occur inside the definition of a class are implicitly inline. Definitions of member functions which occur outside the definition of a class but inside the header file should be explicitly specified as inline.
Last edited on
So, the text from my book makes no sense, because from the code provided with my book the function isnt inline and is normal....

But thanks!
Last edited on
Topic archived. No new replies allowed.