I try to create a new node within a function but it throws up an error because i do not pass an argument, while the other calls where i pass an argument calls my constructor.
Why isnt the default constructor getting called?
Why doesnt the code call default constructor?
hi the cb ide is undergoing mantainance please share ur code on some other ide just now ✓
nothing is visible in the file u shared
updated code now considers the case for 0 but still all but one cases show wrong answer. i’ll wait till ide is available https://ide.codingblocks.com/s/198384
sorry this reply wasnt meant for this doubt. Consider the previous code only
https://ide.codingblocks.com/s/198390 here. I have re-uploaded it. I want to know why the default constructor does not get called
since u havent defined a default constructor
in case u define a paramterized constructor, the compiler does not provide a default constructor , under that circumstance u need to declare a default constructor
so simply define a
node(){
next = NULL;
data = what ever dummy value u want to assign
}
but in the tutorial i’ve seen that a default constructor gets called even when i declare a parameterised constructor
no not possible it is against the c++ fundamental
either tell me the point in the video where default constructor is called without being defined
ok got it. Found it in the video
the link does not have code
https://ide.codingblocks.com/s/200329 This code checks if a LL is a palindrome. The problem with this code was that i did not assign any value to ‘copy’ in line 124. So i want to know what is the difference if i declare the node as (node* copy) and as (node copy)
@tusharnitharwal node copy will create a simple object of node named copy (like we create variable of any other datatype). But node * copy creates a pointer of type node whose name is copy.
I would request you to please raise doubt in the section which you found difficulty instead of reopening old doubts.
If this resolves your doubt mark it as resolved.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.