开发者

How to use objects that got the private copy-constructor and assignment-constructor? [duplicate]

开发者 https://www.devze.com 2023-01-02 21:53 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How to use a object whose copy constructor and copy assignment is private?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How to use a object whose copy constructor and copy assignment is private?

In reading TCPL, I got a problem, as the title refered, and then 'private' class is:

class Unique_handle {
private:   
    Unique_handle& operator=(const Unique_handle &rhs);  
    Unique_handle(const Unique_handle &rhs); 
public:
    //...
} 

The using code is:

struct Y开发者_如何学Go {
    Unique_handle obj;
};

And I want to do such operations

main()
{
    Y y1;
    Y y2 = y1;
    return 0;
}

although, these code are come from TCPL, but I still can not got the solution... Can anybody help me, appreciate.


Evidently you need "friend" declarations in that class, or that class already has static accessors that will create or even assign the instance you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号