Reputation: 22265
I got confused in C++ class definition. Can someone help me out?
I have the original template class defined as such:
template <typename T>
struct SYNCHED_DATA{
SYNCHED_DATA(int r)
{
var_R = r;
}
void set(T* pV)
{
var_T = *pV;
}
//...
private:
//Copy constructor and assignments are NOT available!
SYNCHED_DATA(const SYNCHED_DATA& s)
{
}
SYNCHED_DATA& operator = (const SYNCHED_DATA& s)
{
}
T var_T;
int var_R;
};
and then I use it from another class:
struct THREADS_REPORT{
THREADS_REPORT() //error C2512: 'SYNCHED_DATA<T>' : no appropriate default constructor available
{
}
void getReport(THREADS_REPORT_DATA* pOutReport)
{
//Retrieve report array
sthrd.get(pOutReport);
}
void setReport(THREADS_REPORT_DATA* pReport)
{
//Set report array
sthrd.set(pReport);
}
private:
SYNCHED_DATA<THREADS_REPORT_DATA> sthrd;
//Copy constructor and assignments are NOT available!
THREADS_REPORT(const THREADS_REPORT& s) //error C2512: 'SYNCHED_DATA<T>' : no appropriate default constructor available
{
}
THREADS_REPORT& operator = (const THREADS_REPORT& s)
{
}
};
But I get "error C2512" error at least in two spots in the second class (marked in the code above.) How do I need to change the second class to make it compile?
Upvotes: 0
Views: 1013
Reputation: 2946
You should try initializing THREADS_REPORT::sthrd
in the THREADS_REPORT
constructor via the member initializer list:
THREADS_REPORT(int i) : sthrd(i)
{
}
or provide a default constructor for SYNCHED_DATA
:
SYNCHED_DATA() {}
Upvotes: 4