Jul 22, 2011 at 6:35am Jul 22, 2011 at 6:35am UTC
I'm sorry that line should be
cout << "Address of the object:" << &obj<< endl;
Jul 22, 2011 at 6:40am Jul 22, 2011 at 6:40am UTC
AAString obj();
??? If you are trying to create an object you should change it to AAString obj;
Jul 22, 2011 at 6:45am Jul 22, 2011 at 6:45am UTC
Why? I have used default value for overloaded constructor.
Therefore AAString(int i = 2)
shouldn't be called when I create the object?
Also I need to know why it prints 1 for address of obj
.
Jul 22, 2011 at 7:08am Jul 22, 2011 at 7:08am UTC
No. You should call it like AAString obj = AAString();
which is not correct for your code because it is not clear. May be you can try AAString obj = AAString(3)
or deleting the default constructor.
Your code doesn't print address of an object because there is no object.
Edit: I missed a thing, if you delete AAString();
then AAString obj() should work if you give a value. If you want to use default value then you do AAString obj;
Last edited on Jul 22, 2011 at 7:12am Jul 22, 2011 at 7:12am UTC
Jul 22, 2011 at 7:16am Jul 22, 2011 at 7:16am UTC
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.4
Jul 22, 2011 at 7:56am Jul 22, 2011 at 7:56am UTC
Hmm i think because of the compiler you use, it doesn't recognize it. Try AAString objct = AAString();
Jul 22, 2011 at 8:16am Jul 22, 2011 at 8:16am UTC
rajimrt ,
AAString objct();
What do you think this line is doing? [Hint: it is not creating an object]
Jul 22, 2011 at 8:25am Jul 22, 2011 at 8:25am UTC
@Grey Wolf +1.
You keep trying the same thing. Look AAString objct(5); would work but AAString objct(); wouldn't work. If you want to use the default value you should write AAString objct = AAString();
.
Jul 22, 2011 at 9:10am Jul 22, 2011 at 9:10am UTC
If AAString objct()
does not create an object of AAString what else does it do?
Please give me a reference to read about this.
Jul 22, 2011 at 9:15am Jul 22, 2011 at 9:15am UTC
Thank you firedraco, but your reference does not tell me why any of two constructors are not called when I use AAString objct()
Jul 22, 2011 at 9:23am Jul 22, 2011 at 9:23am UTC
It declares a function called objct that returns an AAString.
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.2
Last edited on Jul 22, 2011 at 9:27am Jul 22, 2011 at 9:27am UTC
Jul 22, 2011 at 9:25am Jul 22, 2011 at 9:25am UTC
why any of two constructors are not called when I use AAString objct()
Because it is creating a call to a function called
objct()
that returns data of type
AAstring
EDIT:
Corrected a mistake.
Last edited on Jul 22, 2011 at 1:39pm Jul 22, 2011 at 1:39pm UTC