Questions about constructors in SOLOLEARN example | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Questions about constructors in SOLOLEARN example

class myClass { public: myClass(string nm) { setName(nm); } void setName(string x) { name = x; } string getName() { return name; } private: string name; }; int main() { myClass ob1("David"); myClass ob2("Amy"); cout << ob1.getName(); } //Outputs "David" It seems that there isn't any difference without void before setName. Am I right?

16th Oct 2018, 2:40 AM
ęž—å…‹ēæ°
1 Resposta
0
Yes, setName doesnt return any value.
22nd Jan 2019, 1:25 PM
LetterC67
LetterC67 - avatar