On Oct 15, 6:37 pm, Piaoger Gong <piao...@gmail.com> wrote:
Hi,
template<class T>
class CMyHandler
{
public:
void DoSomething(int num, CComPtr<T> spiNode)
{
spiNode->Remove();
}
};
int main()
{
CMyHandler<COMClass> handler;
handler.DoSomething();
return 1;
}
The above code will get a link error for ComClass::DoSomething is
unresolved.
No, ComClass::DoSomething is only part of that function's signature.
if I have ComClass::DoSomething called outside of template class. No
link error again.
Is there any method for this issue and I am thirsty for you solution.
Thanks invance,
Piaoger
A function has a signature.
Same goes for non-static member functions
(which additionally includes a this parameter).
void DoSomething( int n ) { } // 1
and
void DoSomething() { }
are two completely different functions.
So if you declare and implement 1 and then try to call DoSomething()
it will be unresolved, as expected. The only part of a function
declaration not considered to be part of its signature is its return
type (if any).
If you were to provide a default value for a given arguement:
void DoSomething( const int n = 5 ) { }
Then you could call DoSomething() since that is really DoSomething(5).
We have a signature match for the function call. DoSomething( const
int ).
There are additional rules in the case you choose to provide default
values to some, not all, parameters. Lookup those details in your fav C
++ book.
Not sure if thats what you are looking for.
Sorry. I made a mistake on my above pseudo code lines: The second
calling should call the method in CMyHandler.
[ comp.lang.c++.moderated. First time posters: Do this! ]