Re: [Dev-C++] Pasing a 'auto_ptr' to a method

Sorry, but your code doesn't seem to be readable. Maybe you should repost,
and make sure that you have semicolons where there should be semicolons,
and that there are no strange braces in the middle of the text.

Look at the declaration of str in the private section of MyClass.

Look at the strange declaration of temp in main.
Look at the strange right brace at end of the assign to tmp.

Also, read up on what auto_ptr is.

Your MyClass constructor declares a local str variable. Didn't you plan on
initializing the str in the private section?

auto_ptr doesn't protect any pointers if you don't make sure that you
always use it.

Please visit
and spend some time, making sure that you understand what it is, and how
to use it.

Or check out the Boost library instead.


On Sat, 25 Aug 2007, Jamiil Abduqadir 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; gives me a number of options, basically the list of overloaded methods. So my question is, what is the proper way to pass 'auto_ptr('s)' to a method?
> class MyClass{
>    private: std::string str*
>    public:
>       MyClass(){ std::auto_ptr<std::string> str(new std::string("unknow"));}
>       MyMethod(const std::string& s){ str = s;} // <== Error??
>    ..........
> }
> main(){
>    std::string temp*
>    std::auto_ptr<std::string> tmp(new std::string("hey!"));}
>    MyClass mc();
>    mc.MyMethod(temp); // <<-- Error??
>    ...
> }

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]