po**************@yahoo.com wrote:
Let's say I have headers Sal.h with this class
class Sal
{
public:
int doit() { return 1;}
};
now I know that the compilier can choose NOT to inline this function.
So if I include this in two different libraries, they both choose to
NOT inline it, and then I link to both libs, am I going to get/should I
get a redefinition error?
You will get a redefinition error.
Say both library A and library B have a source file including this
header. This means that, say, a.cpp and b.cpp, after preprocessing,
will include the code above -- the declaration for class Sal and the
definition for Sal::doit.
If you link these libraries together, the linker will simply see two
definitions for the same name, and issue an error.
If you really want to, you can use "extern inline" to provide a
definition only for inlining -- and then provide another definition
somewhere, probably in a source file for the library, when the compiler
decides not to inline the call.
Something like this:
Sal.h:
class Sal
{
public:
extern inline
int doit() { return 1; }
};
Sal.cpp:
int Sal::doit() { return 1; }