Mail Archives: djgpp/2000/04/17/20:50:22
On Wed, 1 Jan 1997, leon wrote:
> Kalum Somaratna aka Grendel wrote:
> >
> > On Mon, 1 Jan 2001, leon wrote:
> >
> > Well the compiler knows where to get the inlined function from because the
> > inlined function should be defined in a header file.
>
> huh?!
>
> so what about this then:
>
> //the .h file
> class Some
> {
> public:
> Some();
> ~Some();
> inline void Method();
> };
>
> //the .cpp file
> Some::Some()
> {
> ;
> }
> Some::~Some()
> {
> ;
> }
> void Some::Method()
> {
> ;
> }
>
> now if some class uses Some.h file - it will NOT contain the source code
> definition of Method!
Yes...and therefore the Method function won't be inlined in the other
class. It would be replace by just a normal function call with all the
pushes and pops etc....
So if you *really* wan't it to be inlined you have 2 options but both have
to be done in the header (some.h) file
1'st method,
Just put the function body in the class
//the .h file
class Some
{
public:
Some();
~Some();
inline void Method()
{
//your code will go hear
}
};
//end of header
Then as you can see if some.h is included by another class that class has
*acess* to the *code* of the Method function since it is in the header
file. I hope I am clear if not please tell me..
2'd way of doing it is
//the .h file
class Some
{
public:
Some();
~Some();
inline void Method();
};
inline void Some::Method()
{
}
//end of the header file.....
So as you can see the Method function is defined not in the class body
but *still* in the *header* file. So this will also work...
So any module or class that includes some.h can inline the method function
because as before it has access to the Method functions code..
But If the Method functions was in the source (some.cpp) then the above
won't be possible.
Say there is a class called some1 which include some.h..now if the code
for Method is in some.c how is the compiler suppose to inline it (the
compiler hasn't read some.c and it doesn't know the code....)
I hope This is clear,
Best Wishes,
Grendel
Hi, I'm a signature virus. plz set me as your signature and help me spread
:)
- Raw text -