Date: Tue, 11 Jun 2024 13:55:33 +0100
If you do a quick Ctrl + F search on the C++ proposals history on this webpage:
http://www.virjacode.com/cxxproposals/
There are three threads which propose the idea of an "explicit class":
2023 : https://lists.isocpp.org/std-proposals/2023/04/6184.php
2019 : https://lists.isocpp.org/std-proposals/2019/11/0700.php
2004 : http://virjacode.com/cxxproposals/compstdcxx/article18301
2002 : http://virjacode.com/cxxproposals/compstdcxx/article27185
There might be more threads that pose the same idea but call it
something other than "explicit class". So I think we should write a
paper to describe "explicit class" which you would use just like
"class":
explicit class Dog {
public:
int n;
Dog(void) = default;
virtual int Get(void) { return this->n; }
};
So far, here's what I'm thinking the five differences should be in
'class' Vs 'explicit class':
1 - All miranda functions are deleted. Specifically, all
constructors and assignment operators are deleted. If you want any
miranda function, you must write " = default; ".
explicit class Dog {
public:
int n;
Dog(void) = default;
};
2 - When you define a constructor of your own, it is explicit by
default unless you mark it "!explicit".
explicit class Dog {
public:
int n;
!explicit Dog(int);
};
3 - A derived class's member function which overrides a base
class's virtual function must be marked as both 'virtual' and
'override'.
class Frog {
virtual int Func(void) { return 7; }
};
explicit class Dog : public Frog {
virtual int Func(void) override { return 8; }
};
4 - A derived class's virtual member function which has the same
name as a base class's non-virtual member function, must be marked as
"virtual(override !virtual)". This syntax is intentionally
in-your-face and ugly to convey the danger:
class Frog {
int Func(void) { return 7; }
};
explicit class Dog : public Frog {
virtual(override !virtual) int Func(void) { return 8; }
};
5 - You must explicitly write "this->" before every member (both
member variables and member variables). For example the following
won't compile:
explicit class Dog {
public:
int n;
Dog(void) : n(7) {}
virtual int Get(void) { return n; }
};
but the following will:
explicit class Dog {
public:
int n;
Dog(void) : this->n(7) {}
virtual int Get(void) { return this->n; }
};
Note that the constructor's initialiser list has "this->n(7)" instead
of "n(7)", and this is so that you can have a member with the same
name as a base class, as follows:
class n {};
explicit class Dog : public n {
public:
int n;
Dog(void) : n(), this->n(7) {}
virtual int Get(void) { return this->n; }
};
Anyone got any more ideas?
http://www.virjacode.com/cxxproposals/
There are three threads which propose the idea of an "explicit class":
2023 : https://lists.isocpp.org/std-proposals/2023/04/6184.php
2019 : https://lists.isocpp.org/std-proposals/2019/11/0700.php
2004 : http://virjacode.com/cxxproposals/compstdcxx/article18301
2002 : http://virjacode.com/cxxproposals/compstdcxx/article27185
There might be more threads that pose the same idea but call it
something other than "explicit class". So I think we should write a
paper to describe "explicit class" which you would use just like
"class":
explicit class Dog {
public:
int n;
Dog(void) = default;
virtual int Get(void) { return this->n; }
};
So far, here's what I'm thinking the five differences should be in
'class' Vs 'explicit class':
1 - All miranda functions are deleted. Specifically, all
constructors and assignment operators are deleted. If you want any
miranda function, you must write " = default; ".
explicit class Dog {
public:
int n;
Dog(void) = default;
};
2 - When you define a constructor of your own, it is explicit by
default unless you mark it "!explicit".
explicit class Dog {
public:
int n;
!explicit Dog(int);
};
3 - A derived class's member function which overrides a base
class's virtual function must be marked as both 'virtual' and
'override'.
class Frog {
virtual int Func(void) { return 7; }
};
explicit class Dog : public Frog {
virtual int Func(void) override { return 8; }
};
4 - A derived class's virtual member function which has the same
name as a base class's non-virtual member function, must be marked as
"virtual(override !virtual)". This syntax is intentionally
in-your-face and ugly to convey the danger:
class Frog {
int Func(void) { return 7; }
};
explicit class Dog : public Frog {
virtual(override !virtual) int Func(void) { return 8; }
};
5 - You must explicitly write "this->" before every member (both
member variables and member variables). For example the following
won't compile:
explicit class Dog {
public:
int n;
Dog(void) : n(7) {}
virtual int Get(void) { return n; }
};
but the following will:
explicit class Dog {
public:
int n;
Dog(void) : this->n(7) {}
virtual int Get(void) { return this->n; }
};
Note that the constructor's initialiser list has "this->n(7)" instead
of "n(7)", and this is so that you can have a member with the same
name as a base class, as follows:
class n {};
explicit class Dog : public n {
public:
int n;
Dog(void) : n(), this->n(7) {}
virtual int Get(void) { return this->n; }
};
Anyone got any more ideas?
Received on 2024-06-11 12:55:46