Solved

Error 2558 with vector<>

Posted on 2001-06-15
2
286 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now