[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A question on 'auto_ptr'
From: |
John V. Shahid |
Subject: |
Re: A question on 'auto_ptr' |
Date: |
Sun, 26 Aug 2007 15:38:32 -0400 |
On Sat, 2007-08-25 at 06:08 -0700, jalqadir@gmail.com wrote:
> I would like to pass a variable pointer that has been instantiated
> using 'auto_ptr' to a class method, however, the compiler complains
> saying that it does not recognize the method call;
You have to know that Auto-pointers are class objects, not scalar
pointers. They might look like pointers while using them, but they
aren't. If you want to declare a function which takes an auto_pointer,
then declare the function's arguments as auto_ptr<T> object, where "T"
is some specific type or a template type.
> main(){
> std::string temp*
> std::auto_ptr<std::string> tmp(new std::string("hey!"));}
> MyClass mc();
> mc.MyMethod(temp); // <<-- Error??
> ...
> }
Did you realize that "temp" in main is a pointer, and MyMethod is
expecting a reference ? Besides, what does "temp" has to do with
Auto-pointers, isn't it just a regular pointer !!
Cheers,
--
John V. Shahid <jvshahid@gmail.com>