[LC++]Inlining with templated member functions

Uri.Shenderovich at lightscapenet.com Uri.Shenderovich at lightscapenet.com
Thu Jul 4 00:00:09 UTC 2002


Hi,
As far as I know , you problem doesn't related to 'inline'.
The "problem" is with template. Eventhough, your struct isn't templated ,
but you have template member function,
so you have to define you function at same file where declaration resides,
exactly as the case with templated class/structures.
I had once similar problem, and solution was exactly what you already found
out .

Regards,
Uri



                                                                                                                                                     
                      Mark Phillips                                                                                                                  
                      <mark at austrics.com.au>                 To:      tuxcpprogramming at lists.linux.org.au                                            
                      Sent by:                               cc:                                                                                     
                      tuxcpprogramming-admin at lists.l         Subject: [LC++]Inlining with templated member functions                                 
                      inux.org.au                                                                                                                    
                                                                                                                                                     
                                                                                                                                                     
                      01/07/02 11:18                                                                                                                 
                      Please respond to                                                                                                              
                      tuxcpprogramming                                                                                                               
                                                                                                                                                     
                                                                                                                                                     



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


_______________________________________________
This is the Linux C++ Programming List
: http://lists.linux.org.au/listinfo/tuxcpprogramming List








More information about the tuxCPProgramming mailing list