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

Discussion in 'C++' started by indushekara, Jun 3, 2005.

  1. indushekara

    indushekara Guest

    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
     
    indushekara, Jun 3, 2005
    #1
    1. Advertising

  2. indushekara

    Jeff Flinn Guest

    indushekara wrote:
    > 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
     
    Jeff Flinn, Jun 3, 2005
    #2
    1. Advertising

  3. indushekara

    indushekara Guest

    "Jeff Flinn" <> wrote in message
    news:d7pi0p$9kl$...
    > indushekara wrote:
    > > 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


    Thanks this fixed the problem.
    >
    > > };
    > > int main()
    > > {
    > > map<int,A> mapA;
    > > A A1;
    > > mapA.insert(map<int,A>::value_type(1,A1));
    > > return 0;
    > > }

    >
    > Jeff Flinn
    >
    >
     
    indushekara, Jun 3, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Guio
    Replies:
    6
    Views:
    3,264
    chris
    Oct 20, 2004
  2. Replies:
    3
    Views:
    994
    Howard Hinnant
    Apr 20, 2005
  3. Replies:
    1
    Views:
    478
  4. Generic Usenet Account
    Replies:
    10
    Views:
    2,344
  5. cinsk
    Replies:
    35
    Views:
    2,730
    James Kanze
    Oct 11, 2010
Loading...

Share This Page