Home C++ How to define an operator that is inside a nested class
Reply: 0

C++ How to define an operator that is inside a nested class

user985
1#
user985 Published in June 23, 2018, 5:17 pm

I am having trouble with defining an operator that is within a nested class that is also templated. I understand how to declare and define it within the .h file, but I want to declare it in the .h file and define it in a .hpp file. For example:

List.h

template <typename T>
class List {
public:
    class const_iterator {   //nested class
        //....
        const T & operator*() const;
    };
};

Now here is the part I don't quite understand:

List.hpp

#include "List.h"
template <typename T>
typename List <T>::const_iterator & List <T>:: operator*() const //error line
{
    //do stuff
}

The error I am receiving on line 4 of the Line.hpp is:

Out-of-line definition of 'operator*' does not match any declaration in 'List<T>'

I am looking for a solution that involves solely fixing the .hpp file.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311579 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO