Connecting Tech Pros Worldwide Help | Site Map

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

indushekara
Guest
 
Posts: n/a
#1: Jul 23 '05
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


Jeff Flinn
Guest
 
Posts: n/a
#2: Jul 23 '05

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


indushekara wrote:[color=blue]
> 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){};[/color]

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

Jeff Flinn


indushekara
Guest
 
Posts: n/a
#3: Jul 23 '05

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



"Jeff Flinn" <NONONE@nowhere.com> wrote in message
news:d7pi0p$9kl$1@bluegill.adi.com...[color=blue]
> indushekara wrote:[color=green]
> > 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){};[/color]
>
> A(){}
> A( const A& a ){} // canonical copy constructor[/color]

Thanks this fixed the problem.[color=blue]
>[color=green]
> > };
> > int main()
> > {
> > map<int,A> mapA;
> > A A1;
> > mapA.insert(map<int,A>::value_type(1,A1));
> > return 0;
> > }[/color]
>
> Jeff Flinn
>
>[/color]


Closed Thread