0
votes

When I call main() function I get error:

Error 2 error LNK2019: unresolved external symbol "public: __thiscall Signal::Signal(void)" (??0?$Signal@H@@QAE@XZ) referenced in function "public: __thiscall Img::Img(int,int)" (??0?$Img@H@@QAE@HH@Z) c:\Users\Maja\documents\visual studio 2012\Projects\Project6\Project6\Img.obj Project

Can anyone tell me how to set Linker to not call default constructor and to call one that I want?

template <class T> class Signal {

protected: int N;                               // width of array
       int M;
private:   double deltaT;                       // sampling period
       double t0;                           // initial time
           int flag;                            // indicator
public:  
       T* sig;                              // array of type T
       T** sig2D;
       Signal(void);                    // constructor
       Signal (int);                        // constructor
       Signal (int,int);
       Signal (int,double);                 // constructor      
       Signal(int,int,double);
       Signal (int,double,double);          // constructor
       Signal(int,int,double,double);
};


template <class T> class Img:public Signal<T>
{
public:
    Img(void);
    ~Img(void);
    Img(int,int);
};


template <class T> Img<T>::Img(int a,int b){
    Signal(a,b);  // or Signal<T>::Signal(a,b);
}

int main() {

    Img<int> *a=new Img<int>(2,3);
}
1

1 Answers

2
votes

You need to initialise base classes in the initialiser list:

template <class T> Img<T>::Img(int a,int b) :
    Signal<T>(a,b)  // here
{
    // not here
}

Your version tries to default-construct the base object, since it's not mentioned in the initialiser list, then create and destroy a temporary local object.