Sorry, but you cannot learn C++ this way. You are missing the basic fundamentals of C++ if you go on guessing what the language syntax should look like. You must use structured material, whether it is using good books, good tutorials, etc. Otherwise, you'll just throw stuff on the wall, hoping something sticks.
I thought logically it should work.
No, it doesn't work this way. Any book will show you right away how to construct objects.
In the first case when Demo d=100 ( constructor with one argument is called)
It is same as Demo d(100) ->the 1 argument constructor is called
likewise Demo d=100,200 should be like Demo d(100,200) and call the 2 argument constructor (it what i thought)
Throw all of this out the window, it doesn't work. There is something called the comma operator that makes your version uncompilable.
The way you construct objects is very basic and straightforward:
Code:
Demo d(100, 200);
Regards,
Paul McKenzie
Last edited by Paul McKenzie; November 26th, 2012 at 04:59 AM.
Bookmarks