0

Got two questions

#1 Should constructors be under public? #2 Do I include header file of another class (in composition) in the header of the class I'm using it in?

11th Jul 2018, 1:30 PM
Akib
Akib - avatar
1 Resposta
+ 1
#1 Usually constructors are public, because if they are private, you wouldn't be able to instantiate any objects of that class due to a call to a private member from outside the class. However, I say "usually" because there are specific patterns or classes that make use of this, for example: https://www.sololearn.com/learn/713/?ref=app So they don't necessarily must be public, it comes down to what you need. Regarding #2: Yes, if you want to use a class in another file of your project, you have to include its header file in that file, otherwise the compiler doesn't know what that data type is.
11th Jul 2018, 2:53 PM
Shadow
Shadow - avatar