This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Undefined Refrences Templates



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





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]