Stop this now.
Stop this now.
There's something to a #include file.c that makes me shiver.Quote:
Originally posted by Nick
I do this all the time. Usually when I'm using templates or I'm using inline functions.
But hey! that's your choice.
I don't see the need for you to do this for templates. If you want to have your templates defined in a different file, that's fine. But it's a much better practice to have them added to the project on that case.
As for inline functions, I don't get it. Why the heck you want to an include statement for a .c file that defines inline functions, if the compiler will replace all calls to those functions within that same code file?
Finally, if all else fails, what's taken your from renaming those files to .h and feel a little better about it?
Well you can bash me if you like. :D
Go ahead.
No please don't, not on the C++ board. This is stupid.
dittoQuote:
[Please] Stop this now.
Right now, none of the compilers I know of will allow you to write template code will compile in the .cpp because the compiler needs to know the types to create the object file. For example try to compile thisQuote:
I don't see the need for you to do this for templates. If you want to have your templates defined in a different file, that's fine.
That's why the stl and most template code does something like thisCode:// tmp.h
template<class T>
class Tmp {
Tmp();
};
// tmp.cpp
#include "tmp.h"
template<class T>
Tmp<T>::Tmp()
{
}
Code:// tmp.h
template<class T>
class Tmp {
Tmp();
};
#include "tmp.cpp"
// tmp.cpp
template<class T>
Tmp<T>::Tmp()
{
}
If the whole class is inline then it's probably better to have the implementation in a different file. I guess it really depends on what your doing.Quote:
As for inline functions, I don't get it. Why the heck you want to an include statement for a .c file that defines inline functions, if the compiler will replace all calls to those functions within that same code file?
Someone might be tempted to include the .h file which would be bad because you only want the class definition to include the .cpp file.Quote:
Finally, if all else fails, what's taken your from renaming those files to .h and feel a little better about it?
I'm learning about virtual(polymorhism, something like that).