473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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<CMyBase> 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 4305
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<CMyBase> 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<CMyBase> 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.nospam >
wrote in message news:up*************@TK2MSFTNGP11.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<CMyBase> 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<CMyBase> 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**************@TK2MSFTNGP09.phx.gbl...
thanks, but it doesn't solve a problem....

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:up*************@TK2MSFTNGP11.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<CMyBase> 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<CMyBase> 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<CMyBase> CMyBasePtr;
MapBase my_map;
MapBase::iterator 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**************@TK2MSFTNGP12.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<CMyBase> 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 CopyConstructible requirement
of the standard containers. For a suitable replacement, see
boost::shared_ptr<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
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...
5
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...
6
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...
23
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...
1
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....
2
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...
4
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...
28
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...
1
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.