मेरे पास vertex.h में Vertex टेम्पलेट है।यह "घोषणाकर्ता अमान्य" क्या बनाता है? सी ++
20 template<class edgeDecor, class vertexDecor, bool dir>
21 class Vertex;
जो मैं अपने ग्राफ़ टेम्प्लेट में उसका उपयोग: मेरे graph.h से।
मैंने वर्टेक्स टेम्पलेट का सफलतापूर्वक अपने ग्राफ, रिटर्न पॉइंटर्स को वर्टिसेस आदि में उपयोग किया है। अब पहली बार मैं एक वर्टेक्स ऑब्जेक्ट घोषित करने और उसे चालू करने की कोशिश कर रहा हूं, और जीसीसी मुझे बता रहा है कि मेरा 'घोषणाकर्ता' है 'अमान्य'। यह कैसे हो सकता है?
81 template<class edgeDecor, class vertexDecor, bool dir>
82 Graph<edgeDecor,int,dir> Graph<edgeDecor,vertexDecor,dir>::Dijkstra(vertex s, bool print = false) const
83 {
84 /* Construct new Graph with apropriate decorators */
85 Graph<edgeDecor,int,dir> span = new Graph<edgeDecor,int,dir>();
86 span.E.reserve(this->E.size());
87
88 typename Vertex<edgeDecor,int,dir> v = new Vertex(INT_MAX);
89 span.V = new vector<Vertex<edgeDecor,int,dir> >(this->V.size,v);
90 };
और जीसीसी कह रहा है:
graph.h: In member function ‘Graph<edgeDecor, int, dir> Graph<edgeDecor, vertexDecor, dir>::Dijkstra(Vertex<edgeDecor, vertexDecor, dir>, bool) const’:
graph.h:88: error: invalid declarator before ‘v’
graph.h:89: error: ‘v’ was not declared in this scope
मैं जानता हूँ कि यह शायद एक और noob सवाल है, लेकिन मैं किसी भी मदद की सराहना करते हैं जाएगा।
शायद इस समस्या से संबंधित नहीं है, लेकिन क्या आप वाकई चाहते हैं कि "= नया Vertex (INT_MAX)"? क्या आप शायद "vertex" uncapitalised मतलब था (जो मुझे लगता है कि एक typedef है)? वर्टेक्स <...> में वास्तव में एक सीटीओआर वर्टेक्स/वर्टेक्स पॉइंटर ले रहा है? –