你好我是新來的C++,使用std :: string中的boost共享指針來分配變量
我想在字符串上使用共享指針。
class Test{
private:
void test(std::string* str);
boost::shared_ptr<std::string> sample;
};
void Test::test(std::string* str) {
sample.reset(str); //This is not working.
}
任何人都可以告訴我什麼是錯?
不你的編譯器告訴你什麼是錯的? – Nick 2013-05-08 07:51:20
不是你的問題,但在字符串上使用shared_ptr看起來像是矯枉過正。你有任何理由不只是使用純字符串,'std :: string sample;'?除了其他任何東西'std :: string'都可以使用引用計數來實現,在這種情況下'boost :: shared_ptr'只是一種浪費。 –
john
2013-05-08 07:53:26
它不起作用?調用者創建的'str'參數如何? – hmjd 2013-05-08 07:55:23