[solved]Check this code in cpp
Why the constructor needs to be public and why the code throws error if I changed "Time" to "time" everywhere? https://code.sololearn.com/cdRdO0SRY42j/?ref=app
Actually in Java there are access modifiers for constructors. Java constructors are public by default but you can set them private. In c++ you should give a explicit access specifier for constructors. For me there was no reason to do so (private constructors). But then I read this: https://www.google.com/amp/s/www.geeksforgeeks.org/can-constructor-private-cpp/amp/ I found some real life examples of private constructors.
HonFu You are 100% right it's Sololearn 👼
HonFu 🤫I googled it
Public members may be accessed from anywhere outside of the class, while access to private members is limited to their class and friend functions. Your constructor must be public in order to call it outside your class. time is not(Thank you HonFu for pointing it out) a native function/built-in of the language.
Kevin Star, but doesn't it belong to std? I tried by deleting the 'using std' line, but it still didn't work ...
Hm, is it maybe a Sololearn thing? Time isn't really a keyword, but a function, from ctime, isn't it? So normally, in my thinking, it should sit in std. But Sololearn environment sometimes seems to auto-include stuff...
Kevin Star, did you cross-check on your PC?
Kevin Star But in Java also we see that there is nothing like access modifiers for constructors. Because they should always be called whenever an object is created 🤔... Also thanks for that time keyword
Albert Margaryan, please don't use the question threads of other people for your advertising!
Thanks Kevin Star
The constructor has to be public to make it visible outside the class you have declared it. If it were private you cannot call it from inside the main...