[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Error 2558 with vector<>

I've defined a class as follows:

class CDriverInfo
{
public:
     GUID guidCopy;
protected:
     LPGUID lpGuid;
     std::string desc;
     std::string name;

public:
     CDriverInfo() { lpGuid = 0; }
     CDriverInfo( LPGUID newguid, std::string newdesc, std::string newname);
     CDriverInfo(CDriverInfo &copy);
     CDriverInfo& operator=(const CDriverInfo &copy);
     ~CDriverInfo();

     void Clear(void);

     void SetGUID(LPGUID newguid);
     void SetDesc(std::string newdesc);
     void SetName(std::string newname);
     void SetInfo( LPGUID newguid, std::string newdesc, std::string newname);

     LPGUID GetLPGUID(void) { return lpGuid; }
     GUID GetGUID(void) { return guidCopy; }
     std::string GetDesc(void) { return desc; }
     std::string GetName(void) { return name; }
};

In my program, I create a vector<CDriverInfo> and call its push_back() function with a CDriverInfo as the argument:

vector<CDriverInfo> gDDDrivers;

CDriverInfo temp;
temp.SetInfo( guid, desc, name );

gDDDrivers.push_back( temp );

When I compile my project in VC6, I get the following error:

Compiling...
Graphics.cpp
...vc98\include\xmemory(34) : error C2558: class 'CDriverInfo' : no copy constructor available
...vc98\include\xmemory(66) : see reference to function template instantiation 'void __cdecl std::_Construct(class CDriverInfo *,const class CDriverInfo &)' being compiled

MSDN says that error 2558 might occur if your class's constructor is private, but mine is not. How can I fix this?

Ask me if you need more info.
0
TookH
Asked:
TookH
1 Solution
 
JackThorntonCommented:
The canonical copy constructor takes a const reference as a parameter, e.g. MyClass(const MyClass &copy). I noticed your copy constructor takes a non-const reference. The STL templates do a lot of complex and strange stuff; it may very well be that the basic problem is an attempt to pass a const reference to the constructor, which doesn't make the const guarantee.

Try it and let me know if this fixes it.

- jack
0
 
TookHAuthor Commented:
Aha! It works perfectly. I guess that's what I get for using a Borland C++ 4.5 book as a reference. :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now