Undefined Refrences Templates

Ashish Gupta ashishg@in.niksun.com
Tue Feb 5 03:54:00 GMT 2002


Hi,

I am having problems linking with g++. I have the following

// ABC.h

template<class Foo>
class ABC {
        Foo foo;
        PQR pqr;
        void writeToMe(int i);
public:
       void writeTo() {
               writeToMe(1);
            }
  .........................................
  .........................................
}


template<class whoYou>
class Manager {
        whoYou who;

public:
        void whoDunnit();
}


// abc.cc

#include "abc.h"

template<class Foo> void abc<Foo>::writeToMe(int i) {

        cout << i;
}


// PQR.h

template<class LinkF>
class PQR {
         LinkF lf;

        public :
                void anyMethod();
}


//AnyClass.h
class Parent {
public:
    virtual void whoYou ();
}

class AnyClass : public Parent {
            public:
                void whoYou();
                  .....................

}

//PQR.cc
#include "PQR.h"
#include "abc.h"

typedef  PQR<AnyClass> pqr;
typedef  Manager<pqr> manager;
typedef  ABC<manager> abc;


template<class LinkF> void PQR<LinkF>::anyMethod(){
......................................................
.....................................................
}


The basic idea is that I have ABC which is a "nested" template class.
The program compiles fine but on linking I get undefined references to
writeToMe method of the ABC class from the method whoYou of Parent, even

though the method is not referenced from there. Could you please suggest

any case in which this can happen. I am using  gcc version 2.95.2.
Please help.

Regards
Ashish Gupta






More information about the Gcc-help mailing list