Microsoft KB Archive/249045: Difference between revisions
From BetaArchive Wiki
m (Text replacement - "<" to "<") |
m (Text replacement - "&" to "&") |
||
(One intermediate revision by the same user not shown) | |||
Line 88: | Line 88: | ||
}; | }; | ||
template<char MyClass::*member_ptr | template<char MyClass::*member_ptr> | ||
class AnotherClass { | class AnotherClass { | ||
private: | private: | ||
Line 98: | Line 98: | ||
int main() | int main() | ||
{ | { | ||
AnotherClass<& | AnotherClass<&MyClass::a> var1; | ||
AnotherClass<& | AnotherClass<&MyClass::b> var2; //<<<< Causes compiler error. | ||
return 0; | return 0; | ||
} | } | ||
Line 111: | Line 111: | ||
}; | }; | ||
template<typename MbrType, typename ClassType | template<typename MbrType, typename ClassType> | ||
class AnotherClass { | class AnotherClass { | ||
private: | private: | ||
Line 123: | Line 123: | ||
int main() | int main() | ||
{ | { | ||
AnotherClass<char,MyClass | AnotherClass<char,MyClass> var1(&MyClass::a); | ||
AnotherClass<char,MyClass | AnotherClass<char,MyClass> var2(&MyClass::b); | ||
return 0; | return 0; | ||
} | } |
Latest revision as of 11:34, 21 July 2020
Article ID: 249045
Article Last Modified on 7/5/2005
APPLIES TO
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
This article was previously published under Q249045
SYMPTOMS
The compiler generates an error such as the following when a pointer-to-member is used as a class template parameter.
CAUSE
This C++ language feature has not yet been implemented in Visual C++.
RESOLUTION
To not use the pointer-to-member as a template argument, pass it as a parameter to the class constructor.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
MORE INFORMATION
Use the following sample code to reproduce the behavior:
#ifdef BUG struct MyClass { char a,b; MyClass() : a('a'), b('b') {}; }; template<char MyClass::*member_ptr> class AnotherClass { private: MyClass m_var; public: char value() { return m_var.*member_ptr; } }; int main() { AnotherClass<&MyClass::a> var1; AnotherClass<&MyClass::b> var2; //<<<< Causes compiler error. return 0; } #else // WORKAROUND struct MyClass { char a,b; MyClass() : a('a'), b('b') {}; }; template<typename MbrType, typename ClassType> class AnotherClass { private: MyClass m_var; MbrType ClassType::*member_ptr; public: AnotherClass(MbrType ClassType::*mem_ptr) : member_ptr(mem_ptr) {} char value() { return m_var.*member_ptr; } }; int main() { AnotherClass<char,MyClass> var1(&MyClass::a); AnotherClass<char,MyClass> var2(&MyClass::b); return 0; } #endif
Keywords: kbbug kblangcpp kbtemplate kbcpponly kbpending kbcompiler KB249045