Solved

Error 2558 with vector<>

Posted on 2001-06-15
2
292 Views
Last Modified: 2013-12-14
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
Comment
Question by:TookH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
JackThornton earned 100 total points
ID: 6197428
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
 
LVL 1

Author Comment

by:TookH
ID: 6197511
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question