Forward "Pre-declaring" a Class in C++

c++, class, substring

Solution

You could define it inside the class:

class Substring {
    private:
        string the_substring_;
    public:
        // (...)
        typedef set<Substring, Substring::Comparator> SubstringTree;
        static SubstringTree getAllSubstring(string main_string, int min_size);
};

Problem

I have a situaion in which I want to declare a class member function returning a type that depends on the class itself. Let me give you an example: ``` class Substring { private: string the_substring_; public: // (...) static SubstringTree getAllSubstring(string main_string, int min_size); }; ``` And SubstringTree is defined as follows: ``` typedef set<Substring, Substring::Comparator> SubstringTree; ``` My problem is that if I put the SubstringTree definition after the Substring definition, the static method says it doesn't know SubstringTree. If I reverse the declarations, then the typedef says it doesn't know Substring. How can I do it? Thanks in advance.

Original source