map::insert gives compile error when copy constructor is added.

I

indushekara

Hi,
I want to know what is the problem with this code. I am trying to insert in
a map<int,A> where in i have defined the copy constructor for A
I get the following error in VS6.
e:\program files\microsoft visual studio\vc98\include\utility(21) : error
C2558: class 'A' : no copy constructor available
e:\program files\microsoft visual studio\vc98\include\utility(21) :
while compiling class-template member function '__thiscall std::pair<int
const ,class A>::std::pair<int const ,class A>(const int &,const class A &)'

#pragma warning(disable:4786)
#include <map>
using namespace std;
class A{
public:
A::A(){};
A::A(A& a){};
};
int main()
{
map<int,A> mapA;
A A1;
mapA.insert(map<int,A>::value_type(1,A1));
return 0;
}

tfh
Ishekara
 
J

Jeff Flinn

indushekara said:
Hi,
I want to know what is the problem with this code. I am trying to
insert in a map<int,A> where in i have defined the copy constructor
for A
I get the following error in VS6.
e:\program files\microsoft visual studio\vc98\include\utility(21) :
error C2558: class 'A' : no copy constructor available
e:\program files\microsoft visual
studio\vc98\include\utility(21) : while compiling class-template
member function '__thiscall std::pair<int const ,class
A>::std::pair<int const ,class A>(const int &,const class A &)'

#pragma warning(disable:4786)
#include <map>
using namespace std;
class A{
public:
A::A(){};
A::A(A& a){};

A(){}
A( const A& a ){} // canonical copy constructor
};
int main()
{
map<int,A> mapA;
A A1;
mapA.insert(map<int,A>::value_type(1,A1));
return 0;
}

Jeff Flinn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top