मैं जीसीसी/4.7 का उपयोग कर रहा हूं और मुझे टेम्पलेट फ़ंक्शन (या सदस्य फ़ंक्शन) में टेम्पलेट-टेम्पलेट तर्क के साथ कक्षा को तुरंत चालू करने की आवश्यकता है। मैं निम्न त्रुटिटेम्पलेट टेम्पलेट कोड काम नहीं कर रहा है
test.cpp: In function 'void setup(Pattern_Type&)':
test.cpp:17:34: error: type/value mismatch at argument 1 in template parameter list for 'template<template<class> class C> struct A'
test.cpp:17:34: error: expected a class template, got 'typename Pattern_Type::traits'
test.cpp:17:37: error: invalid type in declaration before ';' token
test.cpp:18:5: error: request for member 'b' in 'a', which is of non-class type 'int'
प्राप्त दो पंक्तियों स्निपेट में चिह्नित कोड चलाता टिप्पणी करके, तो एक एक 'मुख्य' लेकिन 'सेटअप' नहीं में में instantiated जा सकता है। मुझे लगता है कि यह दूसरों के लिए भी ब्याज की बात होगी, और मुझे यह समझने में खुशी होगी कि कोड क्यों काम नहीं करता है। यहां कोड
struct PT {
template <typename T>
struct traits {
int c;
};
};
template <template <typename> class C>
struct A {
typedef C<int> type;
type b;
};
template <typename Pattern_Type>
void setup(Pattern_Type &halo_exchange) {
A<typename Pattern_Type::traits> a; // Line 17: Comment this
a.b.c=10; // Comment this
}
int main() {
A<PT::traits> a;
a.b.c=10;
return 0;
}
किसी भी सुझाव और ठीक करने के लिए धन्यवाद! मौरो
एमएसवीसी 10 के तहत संकलित करता है। –