From cf95592c3725fd63cb89a84448df20210b385f15 Mon Sep 17 00:00:00 2001 From: grhawk Date: Fri, 24 Mar 2023 08:12:37 +0100 Subject: [PATCH] A class without constructor (or deleted constructor) can exist. --- ch7/7.46.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ch7/7.46.md b/ch7/7.46.md index 914a28e..547f662 100644 --- a/ch7/7.46.md +++ b/ch7/7.46.md @@ -1,6 +1,24 @@ (a) A class must provide at least one constructor. - True. If the programmer doesn't provide any constructor, the compiler will synthesise one default constructor. + False. + This is valid code: + ``` + #include + + class C { + public: + C() = delete; + static int a; + }; + + int C::a = 1; + + int main() { + std::cout << C::a << std::endl; + return 0; + } + ``` + (b) A default constructor is a constructor with an empty parameter list.