CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Posts
    5

    copy constructor question

    I get an error when compiling the follow code:
    class SomeType
    {
    public:
    SomeType() { };
    SomeType(SomeType& x) {};

    };

    std::vector<SomeType> array;
    SomeType sometype1;
    array.push_back(sometype1);


    I get:
    error C2558: class 'SomeType' : no copy constructor available

    But I defined the copy constructor. If I comment out that line and uses the default copy constructor the code compiles.

  2. #2
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    Try passing a "const SomeType&".

    If the default is sufficient, don't bother adding it at all.

    Jeff

  3. #3
    Join Date
    Aug 2002
    Posts
    5
    Thanks that worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured