0

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 Answer 1

2

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.

3
  • @user3094708: If you have another question, then you should ask another question - it's hard to read bits of code in comments, or to give enough details to describe the problem clearly. If getHeight is public, then it should be accessible. Dec 16, 2013 at 20:44
  • @user3094708: If you have another question, then you should ask another question - as a question, not a comment to this answer. Dec 16, 2013 at 21:26
  • I realize that I can't access even if is public but before declaration in derivation class I should put using Signal<T>::getHeight and it works. Dec 16, 2013 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.