: C++

2010-04-24 14 views
6

"त्रुटि एक प्रकार अपेक्षित हैं, 'classname' मिल गया" निम्नलिखित कोड का उपयोग करना:: C++

template <typename T> 
class node { 
    [. . .] 
}; 
class b_graph { 
friend istream& operator>> (istream& in, b_graph& ingraph); 
friend ostream& operator<< (ostream& out, b_graph& outgraph); 

public: 

    [...] 
private: 
    vector<node> vertices; //This line 

मैं हो रही है:

error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp, class _Alloc> class std::vector’ 
error: expected a type, got 'node' 
error: template argument 2 is invalid 

संकेत लाइन पर। नोड स्पष्ट रूप से बी_ग्राफ से पहले परिभाषित किया गया है जो इसका उपयोग करता है - मैंने यहां क्या किया है?

उत्तर

24

node कक्षा नहीं है, यह एक वर्ग टेम्पलेट है। आप

vector<node<int> > vertices; 

(int एक उदाहरण के रूप में प्रयोग किया जाता है, आप प्रकार आप वास्तव में जरूरत का उपयोग करना चाहिए), यह vector के तत्व प्रकार, उदाहरण के रूप में उपयोग करने का दृष्टांत की जरूरत

+0

ओह! ठीक है। धन्यवाद, यह काम किया। – Bay

+2

धन्यवाद - मुझे खोज करते समय आपका जवाब मिला और उसने मुझे कुछ समय बचाया। –