2013-12-16 56 views
0

當我打電話main()函數,我得到錯誤:錯誤LNK2019:無法解析的外部符號「公用:__thiscall信號

錯誤2錯誤LNK2019:無法解析的外部符號 「公用:__thiscall信號::信號(無效)」(在函數「public:__thiscall Img :: Img(int,int)」(?? 0?$ Img @ H @@ QAE @ HH @ Z)中引用的函數??0?$ Signal @ H @@ QAE @ \用戶\瑪雅\文件\的Visual Studio 2012 \項目\ Project6 \ Project6 \ Img.obj項目

誰能告訴我如何設置鏈接器不調用默認的構造函數,並調用一個我想要的嗎?

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); 
} 

回答

2

您需要初始化在初始化器列表基類:

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

你的版本試圖通過缺省方式構造的基本對象,因爲它不是在初始化器列表中提到,然後創建和銷燬一個臨時的本地對象。

+0

非常感謝! – user3094708

+0

@ user3094708:如果您還有其他問題,那麼您應該提出另一個問題 - 在評論中閱讀代碼很難,或者提供足夠的細節來清楚地描述問題。如果'getHeight'是公共的,那麼它應該是可訪問的。 –

+0

@ user3094708:如果您有其他問題,那麼您應該提出另一個問題 - 作爲問題,而不是對此答案的評論。 –

相關問題