I have a question on constructor and overload?

  • Context:
  • Thread starter Thread starter needOfHelpCMath
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
7 replies · 3K views
needOfHelpCMath
Messages
70
Reaction score
0
Can overload and constructor be in private? for example my overload constructor:
HTML:
class Node {
      
      private:
             int  Nodedata;
             Node *next;
             Node() {next =  NULL; Nodedata = 0;}
             
             Node(int data = 0, Node *nextNode) { //overloaded constructor
             Nodedata = data;
             next = nextNode;
           }
		   };
     public:
           void insertToFront();
           void insertBack();
           void insertMiddle();
 
Physics news on Phys.org
What happens if you try to create an object of the type Node in the main? Or some class other than the Node class.
 
Setting a function, in an object, "private" means that it can only be seen or used by that object. Setting a constructor "private" means that object can only be constructed by the object itself- which hasn't been constructed yet!
 
Joppy said:
What happens if you try to create an object of the type Node in the main? Or some class other than the Node class.

doesn't work ahaha XD but i was just curious if it works
 
needOfHelpCMath said:
doesn't work ahaha XD but i was just curious if it works

Good that you tried! Now read HallsofIvy's post for why.

Never forget the four key principles of object orientated programming!

Quiz: Which key principle does your question mostly relate to?
 
Joppy said:
Good that you tried! Now read HallsofIvy's post for why.

Never forget the four key principles of object orientated programming!

Quiz: Which key principle does your question mostly relate to?

hmmm...i think the principle is to understand constructors and class and how they work together?
 
needOfHelpCMath said:
hmmm...i think the principle is to understand constructors and class and how they work together?

That's not quite what i was getting at :p :D. But good point nonetheless.

Have you learned about the four principles of OO;

Encapsulation, inheritance, polymorphism, and abstraction?
 
Joppy said:
That's not quite what i was getting at :p :D. But good point nonetheless.

Have you learned about the four principles of OO;

Encapsulation, inheritance, polymorphism, and abstraction?

nope never heard of them and i am taking a class on data structures.