473,396 Members | 1,826 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,396 software developers and data experts.

learning auto_ptr

1. What to do to force an auto_ptr release the object it pointing at before
reaching the end of the scope it resides?

2. If a class is defined as:

class Student
{
int nAge;
int nID;
char sAddress[100];
};

And two Student objects are created: student1 and student2.

Using auto_ptr, what should do to make "student1" and "student2" point to
the same address?

Jul 19 '05 #1
4 1806
"newsock" <ne*****@hotmail.com> wrote in
news:CN*********************@bgtnsc05-news.ops.worldnet.att.net:
1. What to do to force an auto_ptr release the object it pointing at
before reaching the end of the scope it resides?
Is this a homework assignment? Look up auto_ptr in your documentation.
One of the member functions has a name that makes it obvious which one
does what you want.
2. If a class is defined as:

class Student
{
int nAge;
int nID;
char sAddress[100];
};
This has only private members.

And two Student objects are created: student1 and student2.

You can't do that because the constructor is private.
Using auto_ptr, what should do to make "student1" and "student2" point
to the same address?


You said student1 and student2 were Student objects, not Student pointers
pointers, so they can't point to anything. It is not clear how you are
using auto_ptr here anyway.

Gregg
Jul 19 '05 #2
Gregg <gr***@invalid.invalid> wrote in
news:Xn********************************@207.69.154 .205:

You can't do that because the constructor is private.


Oops, mea culpa. There was no constructor declared, so it is not private.

Gregg
Jul 19 '05 #3
"newsock" <ne*****@hotmail.com> wrote in message
news:CN*********************@bgtnsc05-news.ops.worldnet.att.net...
Using auto_ptr, what should do to make "student1" and "student2" point to
the same address?


This is a bad idea. The point of auto_ptr is that it autmatically deletes
the object when it goes out of scope. So if two auto_ptr's point to the
same address you will probably get an access violation.
Jul 19 '05 #4
Gregg <gr***@invalid.invalid> wrote in message
news:Xn********************************@207.69.154 .205...
"newsock" <ne*****@hotmail.com> wrote in
news:CN*********************@bgtnsc05-news.ops.worldnet.att.net:
1. What to do to force an auto_ptr release the object it pointing at
before reaching the end of the scope it resides?


Is this a homework assignment? Look up auto_ptr in your documentation.
One of the member functions has a name that makes it obvious which one
does what you want.
2. If a class is defined as:

class Student
{
int nAge;
int nID;
char sAddress[100];
};


This has only private members.

And two Student objects are created: student1 and student2.


You can't do that because the constructor is private.
Using auto_ptr, what should do to make "student1" and "student2" point
to the same address?


You said student1 and student2 were Student objects, not Student pointers
pointers, so they can't point to anything. It is not clear how you are
using auto_ptr here anyway.

Gregg


This is not a homework. That's why the question I posted was not
well-thought one. I just want to use an example here to make sure I know
how to use auto_ptr? Thanks for your help!
Jul 19 '05 #5

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

Similar topics

5
by: gg | last post by:
I am getting the following compilation errors with the following program. My compiler is aCC 03.27 on HP-UX11 - #include <iostream> using namespace std; #include <list> #include <memory>...
4
by: Rein Anders Apeland | last post by:
Consider the following working code: #include <memory> #include <iostream> void print_ptr( const std::auto_ptr< int > & thePtr = std::auto_ptr< int >() ) {
14
by: Andrew | last post by:
Hello all: After spending some time figuring out auto_ptr class' implementation, I decided to write a small article detailing its use of the auto_ptr_ref proxy class to enable construction and...
10
by: dragoncoder | last post by:
Hi all, I am trying to understanding std::auto_ptr<Tclass implementation from "The C++ standard library" by Nicolai Josuttis. He gives a sample implementation of auto_ptr class template in...
9
by: dragoncoder | last post by:
Hi all, I am trying to understand the auto_ptr_ref role in the implementation of auto_ptr<>. I read the information on net but still not 100% sure of it. My plan is as follows. 1. To see the...
39
by: Andre Siqueira | last post by:
Hello all, I have a member function like thist: Query(const std::string & id, std::auto_ptr<Modifiermodif = std::auto_ptr<Modifier>()) when a try to instantiate a Query like ...
10
by: mosfet | last post by:
Hi, Let's say I have a vector of auto_ptr defined like this : vector< auto_ptr<T v; is it allowed ? Is there any side effects ? If it's not a good idea, how can I fix this ?
18
by: Barry | last post by:
struct A { void Print() const { cout << "Print" << endl; } }; auto_ptr<AGet() {
17
by: Ankur Arora | last post by:
Hi All, I'm building a sample application that uses a custom auto_ptr implementation. The program crashes with the following output:- Output (Debug Assertion failed) ----------
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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,...

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.