|
-
January 13th, 2003, 01:01 AM
#1
Function Templates within Class possible ??
I've just discovered Function Templates and would like to implement it within my class. Is this possible?
I've tried doing something like this:
--
class MyClass
{
public:
template <class T> char WriteActionFile(T &incVar)
}
template <class T> char MyClass::WriteActionFile(T &incVar)
{
cout << sizeof T << endl;
}
void main(..)
{
MyClass myObj;
long val=10;
myObj.WriteActionFile(val);
}
--
What happens is VC++6 returns back the error message:
==
error C2893: Failed to specialize function template 'char __thiscall MyClass::WriteActionFile(T &)' - With the following template arguments:
'char'
==
Ok what did i do wrong? I've tried other combos but cant seem to get function templates to work for a specific class? Does this mean function templates can only be implemented within the global namespace? Ideally i would like to have the template prototype within the class declaration and the definition within the source file, that is, I would prefer not to have to inline the function body into the class declaration.
Last edited by quantass; January 13th, 2003 at 01:20 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|