the code below gives the following compiler error:
error C2512: 'MyClass' : no appropriate default constructor
however, commenting out the template variable in the Thing class causes the code to compile!
Supplying a default constructor (as the error indicates) does NOT solve the problem.
Interestingly, removing the copy constructor from the templated class fixes the error as well...
Is this a bug? It sure seems like it, and if it is does someone have a link to the relevant KnowledgeBase article or official statement?
[tt]
#include<stdio.h>
#include<vector>
using namespace std;
template<class T>
class Tempie
{
public:
Tempie(Tempie<T> &other)
{ data = other.data; }
T data;
};
class Thing
{
public:
//comment out the problem variable and it works!
Tempie<int> problem;
int higherdata;
};
class MyClass : public Thing
{
public:
int spheredata;
};
void main()
{
MyClass mc;
vector<MyClass> items;
items.push_back(mc); //error C2512
}
[/tt]
error C2512: 'MyClass' : no appropriate default constructor
however, commenting out the template variable in the Thing class causes the code to compile!
Supplying a default constructor (as the error indicates) does NOT solve the problem.
Interestingly, removing the copy constructor from the templated class fixes the error as well...
Is this a bug? It sure seems like it, and if it is does someone have a link to the relevant KnowledgeBase article or official statement?
[tt]
#include<stdio.h>
#include<vector>
using namespace std;
template<class T>
class Tempie
{
public:
Tempie(Tempie<T> &other)
{ data = other.data; }
T data;
};
class Thing
{
public:
//comment out the problem variable and it works!
Tempie<int> problem;
int higherdata;
};
class MyClass : public Thing
{
public:
int spheredata;
};
void main()
{
MyClass mc;
vector<MyClass> items;
items.push_back(mc); //error C2512
}
[/tt]