+ 1

Constructor ending with a semicolon? Is it correct? (MORE ON CLASSES, FRIEND FUNCTION TOPIC)C++

class MyClass { public: MyClass() { regVar = 0; }; private: int regVar; friend void someFunc(MyClass &obj); };

21st Dec 2017, 10:32 AM
veerendra singh
veerendra singh - avatar
11 Réponses
+ 5
@Veerendra it is fixed now in lesson factory 😊😊
21st Dec 2017, 1:31 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
A constuctor/destructor is a function too. A Function without a return  value And like outside a class definition a function  implementation requires no semicolon. if we place semicolon after constructor then it will terminate the body of constructor and the function is exit without execute any statement in it
21st Dec 2017, 10:53 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
// Cpp program to illustrate the // concept of Constructors #include <iostream> using namespace std; class construct { public:     int a, b;  // Default Constructor  construct()     {   a = 10;   b = 20;     } }; int main() {  // Default constructor called automatically  // when the object is created  construct c; cout << "a: "<< c.a << endl << "b: "<< c.b;     return 1; } this program will help you to understand more
21st Dec 2017, 10:59 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
sorry my mistake i miss to read that semicolon yeah it is a typo they need to fix it
21st Dec 2017, 11:09 AM
GAWEN STEASY
GAWEN STEASY - avatar
0
I'm asking about constructors not friend functions
21st Dec 2017, 10:43 AM
veerendra singh
veerendra singh - avatar
0
so you mean that above code is correct?
21st Dec 2017, 10:56 AM
veerendra singh
veerendra singh - avatar
0
Gwen actually I'm not still getting it like in the lesson of constructor it never says to put semicolon after the braces
21st Dec 2017, 10:58 AM
veerendra singh
veerendra singh - avatar
0
look you are also not putting semicolon after constructor definition
21st Dec 2017, 11:02 AM
veerendra singh
veerendra singh - avatar
0
I understand your program
21st Dec 2017, 11:02 AM
veerendra singh
veerendra singh - avatar
0
and the concept of constructors too,but the code in which sololearn has placed a semicolon after constructor definition is bothering me
21st Dec 2017, 11:04 AM
veerendra singh
veerendra singh - avatar
0
thanks and I bothered you very much sorry for that
21st Dec 2017, 11:11 AM
veerendra singh
veerendra singh - avatar