473,724 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help, please!! <auto_ptr> & VC7 problem!

Hi, all!
I try to convert my existing code written in VC6 to VC7 and have some
problem with stl auto pointer template.

class CColumn;
#include <memory>
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBase* Clone(void) const
{ return MyBasePtr(new MyBase()); }
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong and i
get compiler message C2440: 'return' : cannot convert from
'std::auto_ptr< _Ty>' to 'CMyBase*'
}
}

If i change to follow implementation a get other error C2558

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{ return new MyBase());}
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong and i
get compiler message C2558: class 'std::auto_ptr< _Ty>' : no copy constructor
available or copy constructor is declared 'explicit
}
}

Where is a problem?? It's compiled fine in VC6!

Thanks in advance,
Evgeny
Nov 16 '05 #1
5 4332
Evgeny wrote:
Hi, all!
I try to convert my existing code written in VC6 to VC7 and have some
problem with stl auto pointer template.

class CColumn;
#include <memory>
you probably had a using namespace std in here too.
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBase* Clone(void) const
{ return MyBasePtr(new MyBase()); }
Why is the function defined as returning CMyBase* if you want to return an
auto_ptr?
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong
and i get compiler message C2440: 'return' : cannot convert from
'std::auto_ptr< _Ty>' to 'CMyBase*'
}
Likewise?
}

If i change to follow implementation a get other error C2558

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{ return new MyBase());}
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong
and i get compiler message C2558: class 'std::auto_ptr< _Ty>' : no
copy constructor available or copy constructor is declared 'explicit
Likewise?
}
}

Where is a problem?? It's compiled fine in VC6!


VC6 had a seriously non-conformant implementation of std::auto_ptr. Try
something like this:

#include <memory>
using std::auto_ptr;

class CMyBase;
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{
return CMyBasePtr(new CMyBase());
}
};

class CMyTest : public CMyBase
{
virtual CMyBasePtr Clone(void) const
{
return CMyBasePtr(new CMyTest());
}
};

-cd
Nov 16 '05 #2
thanks, but it doesn't solve a problem....

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:up******** *****@TK2MSFTNG P11.phx.gbl...
Evgeny wrote:
Hi, all!
I try to convert my existing code written in VC6 to VC7 and have some
problem with stl auto pointer template.

class CColumn;
#include <memory>


you probably had a using namespace std in here too.
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBase* Clone(void) const
{ return MyBasePtr(new MyBase()); }


Why is the function defined as returning CMyBase* if you want to return an
auto_ptr?
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong
and i get compiler message C2440: 'return' : cannot convert from
'std::auto_ptr< _Ty>' to 'CMyBase*'
}


Likewise?
}

If i change to follow implementation a get other error C2558

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{ return new MyBase());}
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong
and i get compiler message C2558: class 'std::auto_ptr< _Ty>' : no
copy constructor available or copy constructor is declared 'explicit


Likewise?
}
}

Where is a problem?? It's compiled fine in VC6!


VC6 had a seriously non-conformant implementation of std::auto_ptr. Try
something like this:

#include <memory>
using std::auto_ptr;

class CMyBase;
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{
return CMyBasePtr(new CMyBase());
}
};

class CMyTest : public CMyBase
{
virtual CMyBasePtr Clone(void) const
{
return CMyBasePtr(new CMyTest());
}
};

-cd

Nov 16 '05 #3
It's strange. I've create new console application project and add my simple
classes.
In this project it already compiled!
Possible in my really project previouse includes generates a problem?

"Evgeny" <ev*****@yahoo. com> wrote in message
news:u7******** ******@TK2MSFTN GP09.phx.gbl...
thanks, but it doesn't solve a problem....

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:up******** *****@TK2MSFTNG P11.phx.gbl...
Evgeny wrote:
Hi, all!
I try to convert my existing code written in VC6 to VC7 and have some
problem with stl auto pointer template.

class CColumn;
#include <memory>


you probably had a using namespace std in here too.
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBase* Clone(void) const
{ return MyBasePtr(new MyBase()); }


Why is the function defined as returning CMyBase* if you want to return an auto_ptr?
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong
and i get compiler message C2440: 'return' : cannot convert from
'std::auto_ptr< _Ty>' to 'CMyBase*'
}


Likewise?
}

If i change to follow implementation a get other error C2558

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{ return new MyBase());}
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong
and i get compiler message C2558: class 'std::auto_ptr< _Ty>' : no
copy constructor available or copy constructor is declared 'explicit


Likewise?
}
}

Where is a problem?? It's compiled fine in VC6!


VC6 had a seriously non-conformant implementation of std::auto_ptr. Try
something like this:

#include <memory>
using std::auto_ptr;

class CMyBase;
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{
return CMyBasePtr(new CMyBase());
}
};

class CMyTest : public CMyBase
{
virtual CMyBasePtr Clone(void) const
{
return CMyBasePtr(new CMyTest());
}
};

-cd


Nov 16 '05 #4
I found, that a problem occured, when CMyBasePtr is a member of another stl
map, defined as follow
typedef map<int, CMyBasePtr> MapBase;
itr->second - generates compiler error C2558: class 'std::auto_ptr< _Ty>' :
no copy constructor available or copy constructor is declared 'explicit
see follow code:

#include <memory>
class CMyBase;
typedef auto_ptr<CMyBas e> CMyBasePtr;
MapBase my_map;
MapBase::iterat or itr = my_map.begin();
itr->second - compiler error C2558

Where is a problem, please?
What should i defined in addition?
Thanks in advance

"Evgeny" <ev*****@yahoo. com> wrote in message
news:uJ******** ******@TK2MSFTN GP12.phx.gbl...
Hi, all!
I try to convert my existing code written in VC6 to VC7 and have some
problem with stl auto pointer template.

class CColumn;
#include <memory>
typedef auto_ptr<CMyBas e> CMyBasePtr;

class CMyBase
{
virtual CMyBase* Clone(void) const
{ return MyBasePtr(new MyBase()); }
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong and i get compiler message C2440: 'return' : cannot convert from
'std::auto_ptr< _Ty>' to 'CMyBase*'
}
}

If i change to follow implementation a get other error C2558

class CMyBase
{
virtual CMyBasePtr Clone(void) const
{ return new MyBase());}
}

class CMyTest : public MyBase
{
virtual CMyBase* Clone(void) const
{
return MyBasePtr(new CMyTest()); - this line detected as wrong and i get compiler message C2558: class 'std::auto_ptr< _Ty>' : no copy constructor available or copy constructor is declared 'explicit
}
}

Where is a problem?? It's compiled fine in VC6!

Thanks in advance,
Evgeny

Nov 16 '05 #5
Evgeny wrote:
I found, that a problem occured, when CMyBasePtr is a member of
another stl map, defined as follow
typedef map<int, CMyBasePtr> MapBase;
itr->second - generates compiler error C2558: class
'std::auto_ptr< _Ty>' : no copy constructor available or copy
constructor is declared 'explicit


std::auto_ptr<T > is not suitable for use in any standard containers. This
is because std::auto_ptr<T > does not meet the CopyConstructib le requirement
of the standard containers. For a suitable replacement, see
boost::shared_p tr<T> at www.boost.org.

-cd
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1613
by: Pudibund | last post by:
Ok, I've spent nearly a week trying to sort what should be an easy task to accomplish but I'm totally flumoxed! I want to do something pretty simple... 1. display image1 2. wait until image1 is drawn to the screen
5
2292
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action to either a) generate numbers b) Prompts a user to locate a web page c) go to previous page in history list d) Loads next page in history list e) Promps the user for a URL and loads the web page in a new window f) and Re-Sizes the window. ...
6
2144
by: John Baker | last post by:
Hi: As those who have looked at this newsgroup recently will realize, I am a neophyte with Access, although I have experienced with Approach (the Lotus product). There are things I could easily do in Approach that appear to require some subtle and complex manipulation in Access. Herein lies my present problem. I have a number of tables, including one called "tblPO", which contains purchase orders. Some of the details of these change...
23
3280
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
1
3439
by: Chua Wen Ching | last post by:
Hi there, I have some problems when reading XML file. 1. First this, is what i did, cause i can't seem to read "sub elements or tags" values, so i place those values into attributes like this. Before: ----------
2
1242
by: John Saunders | last post by:
Ok, this is what I need to accomplish. We have a huge excel file that comes in daily. I need the server to grab this excel file each day and import the data into a SQL database. Once that is accomplished, I want the web app to allow the user to search any data in the table. This is overwhelming to me.. I don't know where to begin. The excel file has 193 fields and tons of records. Any advice on this would help me tremendously.
4
2278
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this dataSet updating lark when i realised that i think i am right back at square 1!!! Here's my scenario - i have a SQLDB and i retrieve all my data from that into a dataset and display this to a datagrid(WebForm). I have got this grid sorted and...
28
10270
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event is firing twice (95% of the time) on the page. the other 5% it only fires once. there's no
1
1438
by: ismailc | last post by:
Hi, I need help please i usually code in coldfusion but now i want to create 2 text html files where i pass a parameter on href? This normally works in coldfusion! Page1 <a href="test.htm?test=100','','height=300,width=300"> Page2 <html>
0
2756
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a DLPayDate I created the query in design view of access. Current Query: SELECT PaymentCalculator2.ID, PaymentCalculator2.RecDate, DateAdd("w",5+1,) AS DLPayDate, DateAdd("w",5,) AS DLPayDate2 FROM PaymentCalculator2 WHERE...
0
8741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9241
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9160
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8062
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6685
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4764
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2149
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.