Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STL problem in VS 7.1 (2003) ?

Status
Not open for further replies.

kixix

Programmer
Apr 4, 2005
3
US
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]
 
Try defining both a default constructor and a copy constructor for MyClass.

Also, have main return an int.
 
AAAAARRRRGGG
freakin const keyword, gets me every time it can

I figured it out :)

[copy constructors need their input to be const]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top