2016-04-07 16 views
1

robot.h:11:20: error: expected identifier before numeric constant Queue SQ(10);Üye değişken başlatma hatayı Bu konuda bir hata alıyorum neden anlamıyorum

struct Robot 
{ 
    string m_name; //robot name 
    Queue<string> SQ(10); //queue of services 
    int m_timer; //time til robot is done 
    string m_lastService; //most recent service 
}; 

verir. (10) 'u aldığımda, varsayılan kurucuyu kullandı ve iyi çalışıyor. İşte sıra sınıfı.

template <typename T> 
class Queue : public AbstractQueue<T> 
{ 
    private: 
    T* m_array; 
    int m_front; 
    int m_back; 
    int m_capacity; 
    int m_size; 
    public: 
    Queue(); 
    Queue(int max); 
    void setMax(int max); 
    bool isEmpty() const; 
    const T& front() const throw (Oops); 
    const T& back() const throw (Oops); 
    void enqueue(const T& x); 
    void dequeue(); 
    void clear(); 
    ~Queue(); 
}; 

Ben Kuyruk sınıfın başka beyanı kullanılan ve ana çalıştı, ama nedense o yapı içinde çalışmaz, burada ana

Queue<Robot> R(10); 

cevap

1

yapabilirsiniz beyan budur Üye değişken başlatmada kullanılan varsayılan olmayan yapıcıyı belirtin.

Kullanılacak Queue yapıcısını belirtmek için member initializer list ile bir kurucu sağlayabilirsiniz.

struct Robot 
{ 
    string m_name; //robot name 
    Queue<string> SQ(); //queue of services 
    int m_timer; //time til robot is done 
    string m_lastService; //most recent service 
    Robot() : SQ(10) {} 
}; 

ya da kullanımı default member initializer (11 C++ çünkü):

Queue<string> SQ{10}; 
İlgili konular