简体   繁体   中英

How to separately define a nested class member function with the outer class templated?

I am writing a template class with a inner struct(public class). Now I have problems while defining the member function of the inner struct.

In the header file,

template <typename T>
class TMatrix {
    ...
    struct Triplet {

        void nop() const;

    };
    ...
};

To define the function nop, in another cpp file I wrote

template <typename T>
void TMatrix<T>::Triplet::nop() {...}
// or
// void typename TMatrix<T>::Triplet::nop() {...}

But both of the two form don't compile. g++ says

error: expected unqualified-id before ‘)’ token

How can I correctly define this function separately?

Everything is working fine except you have to add const in function definition

template <typename T>
void TMatrix<T>::Triplet::nop() const {}  // <--const is added in function declaration

You can check working example here

http://ideone.com/Yeio3w

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM