2017-03-07 87 views
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&)’ 
+1

您的代碼在MinGW 5.3上編譯並運行時沒有任何問題。請注意,C++中不需要'typedef struct'語法,請問您使用此語法的原因是什麼 –

回答

1

看起來類型ssbroadcast_server::Hybrid_Message_st,而Singleton正在使用Hybrid_Message_st。請注意類型之間名稱空間的差異。

有可能您的代碼中的某處是using broadcast_server

+0

謝謝。 包含在標題中包含兩次。 –