Solved

Error 2558 with vector<>

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 71
getting a fire fox page (view page source ) in c++ 6 42
Visual Studio Debugging 3 121
Angular JS Route 3 45
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

932 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

11 Experts available now in Live!

Get 1:1 Help Now