Re: Templates and Non-Inline Functions



Yes you did. SomethingElse is not marked as inline and the body is not
within the class definition, so it's not going to be inlined.

AliR.

"Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx> wrote in message
news:ON9JieYQGHA.2436@xxxxxxxxxxxxxxxxxxxxxxx
AliR,

Ok here is the deal, when defining a class template. The implementation
has
to be in the .h file, because when there is a decleration the compiler
needs
both the definition and the decleration at the same time. Now that
explains
why you need to have everything in the h file.

Right, I understood that part.

Now as far as inlined template functions. It's up to you if you want
them
inlined or not

template<class T>
class MyTemp
{
int GetSomething(...) { reutrn something; } <---- inlined
int GetSomethingElse();
};

//not inlined
template<class T>
int MyTemp<T>::GetSomethingElse(...)
{
return somethingelse;
}

It this doesn't help you might want to ask the C++ experts at
comp.lang.c++ newsgroup.

So even if the above implementation of GetSomethingElse() appears in the
header file, it won't be an inline function because the implementation is
not defined within the class definition. Did I understand correctly?

Thanks.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com




.



Relevant Pages


Loading