Re: C++ puzzle - how to get this to compile ?
On 12/2/2011 1:28 AM, Juha Nieminen wrote:
OSS542<jhart666@gmail.com> wrote:
class cls2
{
friend void cls1::fun1();
};
class cls1
{
cls2 mbr1;
public:
void fun1();
};
In principle there's no technical reason why that couldn't be done. It's
just a question of lacking syntax in the language.
It would be useful if one could, somehow, declare member functions before
the class definition is known. (If the class then fails to define the
declared member function, a linker error would happen.) This can be done
with namespaces, but not with classes.
I'd say a syntax like this would be enough:
class A;
int A::foo(int, int);
Anyone see any problem with that?
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.
V
--
I do not respond to top-posted replies, please don't ask