Re: C++ puzzle - how to get this to compile ?
Victor Bazarov <v.bazarov@comcast.invalid> wrote:
I think you're advocating forward-declaration of member functions. In
that case the full qualification should be allowed for forward-declaring
static, virtual, default, pure virtual and const members of the class.
Basically there shouldn't be a problem if you want to write
virtual int A::foo(int,int) const = 0;
outside the class itself. However, currently the grammar does not allow
the keyword 'virtual' to be used outside a class definition, and also
defines a different meaning of the keyword 'static'.
I don't see "any problem" except that the grammar needs to be made even
more complicated to allow out-of-the-class-definition member declarations.
Perhaps if there was a way to do a kind of "partial declaration" of a
class. In other words, you declare a class and some of its member functions
(and other stuff, such as member types and variables), but it's still not
a full class declaration (iow. you still can't instantiate the class
based solely on this partial declaration).
I don't have a good idea for a syntax for this. I get the feeling that
the standardization committee abhors the addition of new reserved keywords
(in order to, I suppose, minimize name collisions with existing code), and
none of the existing reserved keywords that I can think of sound like a
good fit for this. Perhaps the least horrible keyword I can think of
would be 'namespace'. It could go something like this:
namespace class A // partial declaration of A
{
public:
virtual int foo(int, int) const = 0;
int bar(int);
int bar(int) const;
class InnerClass;
};
Now it would be possible to refer to those member functions and types of
the class A (and even call them using a reference/pointer of type A) before
we have a full definition.