Inheritance does not work when linking shared library ...

HI,

i have a problem with inheritance in shared library and an application ...
I have a library containing a very simple template "tmpl" and a derived class
"clsDerived".

If i try to use "clsDerived" in an application, i get the error
"unkown reference to tmpl<...>::setSome()", but see below ...


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

template<typename TypeSyn> tmpl{

     TypeSyn* field1;
     /* ... there are some more fields ... */

     public: 
	TypeSyn getSome();
	void setSome(TypeSyn a);

      private:
	....
      protected:
	....
}


Implementation of the methods is done then this way ...
1
2
3
4
5
6

template <typename TypeSyn>
void tmpl<TypeSyn>::setSome(TypeSyn* data){
   
  /* set the content of "field1"  ... */
}



Then i add a derived class with "TypeSyn = double"

1
2
3
4
5
6
7
8
9
10
11
12
class cslDerived : public tmpl<double>{

public:

  /* all fields derived ... the constructor should be assumed to be as 
    simple as possible */
  void veryOwnMethod(double);
private:
protected:

}


the very own method is implemented like ( but that does not matter i think ...)

1
2
3
4
5
6

void clsDerived::veryOwnMethod(double some){

  /* some functionality here .... */

}


What i get is now an "undefined refernce to tmpl<double>::setSome(double) ...
if i try to use the class "clsDerived" in an application ...
I think it is quite a standard mistake i am making and i hope i have given the relevant
code. maybe i need some special compilerflags or something else ...
However, i did not need when i did only use a class. That is why i think it is the way i use inheritance and templates , but i don't know what it is exactly. A link for a tutorial with emphasis on linking a shared library AND inheritance and templates would help me as well, i think.

If i have left out something relevant, please let me know.

Best regards and thanks for reading,
...
Last edited on
External linkage doesn't work good with templates. You are more or less forced to define setSome in the header file.
Well, it seems so .. i found some other notes on that on the internet and i am disappointed ...
But well, whatever, it will work somehow ... it should be enough to put all template methods into the header file, no ??
Topic archived. No new replies allowed.