2017-04-22 83 views
0

喜IM存儲一個矢量對象共享指針和調用打印過程打印出來,但它拋出一個錯誤,因爲「敵不過呼叫**」下面是代碼將共享指針存儲矢量對象拋出錯誤?

namespace info 
{ 
typedef struct { 
     std::string Yes; 
     std::string NO; 
     int ID_NO; 
} mystruct; 

typedef std::vector<mystruct> myvector; 

typedef struct { 
     bool status; 
     std::shared_ptr<myvector> shared; 
} Myreturn; 

} 

void printmyinfo(const std::shared_ptr<info::mystruct>& printval) 
{ 
     if(printval == NULL) 
     { 
       cout<<"Sorry no value exist"<<endl; 
       return; 
     } 
     // here is print code which is good. 
} 


int main() 
{ 
     info::mystruct *structinfo=new mystruct ; 
     structinfo->yes="okay"; 
     structinfo->ID_NO=10; 
     info::myvector vectorobject; 
     vectorobject.push_back(structinfo); 
     info::Myreturn *returnobj=new Myreturn; 
     returnobj->shared(myvector)// bad how to store vector in share pointer of Myreturn structure 

//如何用myvector填充Myreturn.shared並傳遞給printmyinfo? printmyinfo(myvector)//壞 }

在這一行returnobj.shared(structinfo)錯誤thow請幫我解決它感謝

如何填寫Myreturn.shared與myvector,並傳遞給printmyinfo?

+0

對不起我的錯誤是在堆不是堆疊。 – pravakar

回答

0

也許你想要這個。

returnobj.shared = shared_ptr<info::myvector>(&structinfo) // 

還糾正最後一行,您的printmyinfo()參數類型不匹配。

+0

我需要使用下面Myreturn結構共享指針存儲vectorobject typedef結構{ BOOL狀態; 的std :: shared_ptr的共享; } Myreturn; – pravakar

+0

共享指針堆棧分配的對象是沒有作用的。 –