Can you call public methods from a constructor in C++?
-
Can I call public function in constructor to initialize the private member variables? I Googled and found one should not use virtual functions and public functions in constructor, whereas we can always use private member functions in constructor.
-
Answer:
There is no prohibition against calling public methods from a constructor in C++. Nothing wrong with it at all. There is also nothing wrong with public methods initializing private variables, or vice versa. Whether a method is public, private, or protected is irrelevantâthose are just access restrictions. There are two things of which a constructor need be mindful: Calling virtual methods and calling functions that manipulate member variables that are initialized later in the constructor. The latter isn't a rule, just common sense, but is an easy mistake to make.
Robert Love at Quora Visit the source
Related Q & A:
- Do you know a good software that can record call conversation?Best solution by Yahoo! Answers
- Is it unsafe to call methods from a thread?Best solution by stackoverflow.com
- how to call methods from a dll from c++?Best solution by Stack Overflow
- Can you call a witness for a pre-hearing at the Employment tribunal?Best solution by Yahoo! Answers
- Can you call a skype call back?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.