auto_ptr问题.
#include <iostream>
#include <memory>
using namespace std;
class A{
public:
A() { cout << "constructor A" << endl; }
~A() { cout << "destructor A" << endl; }
void x() { cout << "A::x()" << endl;}
};
auto_ptr<A> g()
{
auto_ptr<A> p(new A);
return p;
}
int main()
{
auto_ptr<A> ptr;
ptr = g();
}
上面的这段代码,main()函数里的ptr取得g()的返回值,并得到ownership,应该是可以的,但是我用borland command line tool编译器却不能通过。是因为编译器对标准的不完全支持还是这个代码有问题。
谢谢。
问题点数:5、回复次数:7Top
1 楼corrupt(喜欢 睡在床板下 的思考)回复于 2005-11-22 10:33:13 得分 1
偶也想知道 智能 指针 能不能 构造 class A,
偶 一直 没碰到过这样类试的问题Top
2 楼sankt(宠辱不惊,看庭前花开花落;去留无意,望天空云卷云舒.)回复于 2005-11-22 10:49:14 得分 1
用DEV-CPP
Top
3 楼questionprogfan()回复于 2005-11-22 11:00:34 得分 1
corrupt(宗教使人分散,信仰使人团结!!信仰C++) :你的意思我没有理解.智能指针能不能构造class A,?只有用其他的编译器试试了。Top
4 楼pongba(刘未鹏|http://blog.csdn.net/pongba)回复于 2005-11-22 12:00:08 得分 1
ptr.reset(g());Top
5 楼dofeel(do_feel)回复于 2005-11-22 12:15:14 得分 1
这要看编译是否支持标准库了!Top
6 楼questionprogfan()回复于 2005-11-22 12:30:20 得分 0
reset()的参数应该是普通的指针吧.g()的返回值是一个auto_ptr<>.Top
7 楼pongba(刘未鹏|http://blog.csdn.net/pongba)回复于 2005-11-22 12:43:14 得分 0
不好意思,没仔细看,呵呵:)
你这个问题是编译器或库实现的问题;-)Top




