问一个private destructor的问题# Programming - 葵花宝典
s*i
1 楼
我想要create instance ONLY on stack,下面的做法是否正确阿?
class temp
{
private:
~temp() {;}
friend class Final;
};
class Final: virtual public temp
{
//Define as usual
}
=============================
我有点搞不清,如果不用friend的话,会怎么样?比如
class final2
{
public:
static final2* Create() { return (new final2()) ; }
private:
~final2(){} ;
} ;
class child : public final2
{
public:
child(){ ;}
} ;
int main()
{
final2 *f ;
f = final2::Create() ;
}
这个时候我的object是在heap上,还是stack上?
class temp
{
private:
~temp() {;}
friend class Final;
};
class Final: virtual public temp
{
//Define as usual
}
=============================
我有点搞不清,如果不用friend的话,会怎么样?比如
class final2
{
public:
static final2* Create() { return (new final2()) ; }
private:
~final2(){} ;
} ;
class child : public final2
{
public:
child(){ ;}
} ;
int main()
{
final2 *f ;
f = final2::Create() ;
}
这个时候我的object是在heap上,还是stack上?