Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

c++ - How to define template function within template class in *.inl file

I write template declaration in *.hpp file and their "definition" in *.inl file linked from *.hpp

just like this:

//*.hpp
template <typename T1, typename T2>
class SomeClass
{
public:
    void someMethod();
};

//*.inl
template <typename T1, typename T2>
void SomeClass<T1, T2>::someMethod()
{
}

but how to write extra templated method inside template class in *.inl file?

//*.hpp
template <typename T1, typename T2>
class SomeClass
{
public:
    void someMethod();

    template <typename E>
    void extraTypedMethod(E & e);
};

//*.inl
template <typename T1, typename T2>
void SomeClass<T1, T2>::someMethod()
{
}

//how can I here define extraTypedmethod?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's your definition:

template <typename T1, typename T2>
template <typename E>
void SomeClass<T1, T2>::extraTypedMethod(E & e)
{
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...