constructor failed??? [modified]
-
Is This program working ???
cout>>x>>endl;
cin<<ch;try using debuging than you find that why x is not giving right output :) #include "stdafx.h" #include <iostream> using namespace std;
class aa
{public: aa(int t = 5) { x = t; } void print() { cout<<x <<endl; } private: int x;
};
int main(int argc, char* argv[])
{
aa t;
t.print();
cout<<"---------------------"<<endl;aa t1(4); t1.print(); char ch; cin>>ch; return 0;
}
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
modified on Thursday, June 5, 2008 3:41 AM
Shilpi Boosar wrote:
cout>>x>>endl;cin<<ch;
you're not serious, are you ? :~ X| when you don't know what you're talking about, please avoid posting crap, that will avoid the question poster to be confused at last.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Thank you Pallini.I got it... But i found this code can't work. class aa { public: aa():x(5) { }//... }; it said x(5) is not a base class. Thanks once again! :)
If we dream, every thing is possible!
it's because in this class, you don't define a x member...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Is This program working ???
cout>>x>>endl;
cin<<ch;try using debuging than you find that why x is not giving right output :) #include "stdafx.h" #include <iostream> using namespace std;
class aa
{public: aa(int t = 5) { x = t; } void print() { cout<<x <<endl; } private: int x;
};
int main(int argc, char* argv[])
{
aa t;
t.print();
cout<<"---------------------"<<endl;aa t1(4); t1.print(); char ch; cin>>ch; return 0;
}
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
modified on Thursday, June 5, 2008 3:41 AM
-
Shilpi Boosar wrote:
cout>>x>>endl;cin<<ch;
you're not serious, are you ? :~ X| when you don't know what you're talking about, please avoid posting crap, that will avoid the question poster to be confused at last.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Thank you Pallini.I got it... But i found this code can't work. class aa { public: aa():x(5) { }//... }; it said x(5) is not a base class. Thanks once again! :)
If we dream, every thing is possible!
In my sample
//...
was the concise notation for
aa(int t)
{
x = t;
}
void print()
{
cout << x << endl;
}
private:
int x;
};:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Shilpi Boosar wrote:
cout>>x>>endl;cin<<ch;
you're not serious, are you ? :~ X| when you don't know what you're talking about, please avoid posting crap, that will avoid the question poster to be confused at last.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Thans Shilpi. I'm so sorry.It's my fault. I have edited my post... :)
If we dream, every thing is possible!
-
I think now you got the answer why i write that code. :)
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
nope. i still don't understand why you used the wrong operators... cout use <<, not >>
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
I think now you got the answer why i write that code. :)
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
-
nope. i still don't understand why you used the wrong operators... cout use <<, not >>
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ ;P ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toxcct wrote:
so no need to flood the thread
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ ;P ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeOh what happend for your thread I give you 5 but I think it needs to repair. :laugh:
-
Oh what happend for your thread I give you 5 but I think it needs to repair. :laugh:
Thanks my friend. Anyway I don't bother if people don't appreciate my humour. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke