[LC++]Inlining with templated member functions

Mark Phillips mark at austrics.com.au
Mon Jul 1 18:17:06 UTC 2002


Hi,

This list has been a bit quiet.  I have a question though...

I defined a struct with a templated member function thus:

struct MyStruct {
...
   template<typename A> void put(A const& a);
...
};

and later did

template<typename A>
inline void put(A const& a) {
... // do something
}

and in one of my .cc files, I called the "put" function.  I am using
g++ version 2.96, and the linker complained with something along the
lines of:

    undefined reference to void put<Something>(Something const&)

But there should be no need to have a reference, because it should
be inlined!

I moved the implementation of put to inside the struct definition
like so:

struct MyStruct {
...
   template<typename A> void put(A const& a) {
   ... // do something
   }
...
};

and then magically it worked!

Does anyone know anything about why it didn't like the inlining being
done outside the struct definition?

Thanks,

Mark.

-- 
Dr Mark H Phillips
Research Analyst (Mathematician)

AUSTRICS - smarter scheduling solutions - www.austrics.com

Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax   +61 8 8231 4821
Email mark at austrics.com.au





More information about the tuxCPProgramming mailing list