Float the idea: Forward declaring inner classes

75 views
Skip to first unread message

xax...@gmail.com

unread,
Jun 20, 2016, 7:35:29 PM6/20/16
to ISO C++ Standard - Future Proposals
I've never written anything to this list before and am trying to follow the instructions here: https://isocpp.org/std/submit-a-proposal

I'd like to allow forward declarations of inner classes.  Here is a situation I've run into where it seems that forward declaring the inner classes would allow this to work:


class Outer1; // <== potentially optional
class Outer::Inner; //<== NEW


class Outer2; // <== potentially optional
class Outer2::Inner; //<== NEW


template<class T>
class SomeClass {

// !!error: no type named 'Inner' in 'Outer1' <== clang error in current c++
 
typename T::Inner * some_func();
};


class Outer1 : public SomeClass<Outer1> {
 
public:
 
class Inner {
 
};
};


class Outer2 : public SomeClass<Outer2> {
 
public:
 
class Inner {
 
};
};


While there are certainly workarounds, I find this organizational structure to be useful in other languages and would have used it in c++ had it been available.   


The workaround I've found is this, but the code doesn't match my intent nearly as well.  
class Outer1Inner {};
class Outer1 : public SomeClass<Outer1Inner> {};



Thank you for your feedback - either on the actual proposal or on proposal procedure.

--Zac

T. C.

unread,
Jun 20, 2016, 8:42:18 PM6/20/16
to ISO C++ Standard - Future Proposals, xax...@gmail.com

xax...@gmail.com

unread,
Jun 20, 2016, 8:43:18 PM6/20/16
to ISO C++ Standard - Future Proposals, xax...@gmail.com
awesome, thank you.

xax...@gmail.com

unread,
Jun 20, 2016, 8:59:02 PM6/20/16
to ISO C++ Standard - Future Proposals, xax...@gmail.com
Oh.  Less awesome that it was rejected.

T. C.

unread,
Jun 20, 2016, 9:05:24 PM6/20/16
to ISO C++ Standard - Future Proposals, xax...@gmail.com
It was not rejected. According to [1], EWG apparently liked the idea but thought it needs more work.

Nicol Bolas

unread,
Jun 20, 2016, 9:32:33 PM6/20/16
to ISO C++ Standard - Future Proposals, xax...@gmail.com
And FYI: the correct term is "nested classes". The term "inner class" is primarily a Java term that has additional features that C++ nested classes don't have.
Reply all
Reply to author
Forward
0 new messages