0
單例變量中有一個隊列。C++單例結構隊列
但是,當從另一個類推送時,推送值不匹配,並且錯誤繼續。
請。
[單頭]
typedef struct _Hybrid_Message_st
{
int hy_state;
std::string hy_msg;
} Hybrid_Message_st;
class Hybrid_Singleton
{
private:
static Hybrid_Singleton *instance;
Hybrid_Singleton(void){}
public:
~Hybrid_Singleton(void){}
static Hybrid_Singleton* getInstance();
std::queue<Hybrid_Message_st> hy_queue;
int count;
};
[單源]
Hybrid_Singleton* Hybrid_Singleton::getInstance()
{
if(instance == NULL)
{
instance = new Hybrid_Singleton;
}
return instance;
}
Hybrid_Singleton *Hybrid_Singleton::instance = NULL;
[問題?]
Hybrid_Message_st ss;
ss.hy_state = 0;
ss.hy_msg = "Hellow";
Hybrid_Singleton::getInstance()->hy_queue.push(ss);
[錯誤]
error: no matching function for call to ‘std::queue<_Hybrid_Message_st>::push(broadcast_server::Hybrid_Message_st&)’
您的代碼在MinGW 5.3上編譯並運行時沒有任何問題。請注意,C++中不需要'typedef struct'語法,請問您使用此語法的原因是什麼 –