Re: [Dev-C++] Question about class objects
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Teodorescu C. <te...@xt...> - 2002-10-23 12:37:22
|
Daniel Glenfield wrote:
>
>> From: Teodorescu Cristian <te...@xt...>
>> To: dev...@li...
>> Subject: Re: [Dev-C++] Question about class objects
>> Date: Wed, 23 Oct 2002 15:00:56 +0200
>>
>> Daniel Glenfield wrote:
>>
>>>
>>>
>>> When I create a class object, can I call a member function right away?
>>>
>>> I'm thinking that if I have private data I want to initialise when
>>> the object is created I could put in a member function that does it,
>>> but can I call it immediately? Instead of
>>>
>>> MyClass ObjectOne;
>>> ObjectOne.StartUp();
>>>
>>>
>>> I know that a constructor initialisation list will do the same, can
>>> someone show me an example of that as well as I am a little confused
>>> by the syntax.
>>
>>
>> class MyClass{
>> public :
>> MyClass (int x=0){
>> m_intX=x;
>> }
>> private:
>> m_intX;
>> }
>>
>> void main (void ){
>> MyClass a,b(10);
>> //a.m_intX=0 and in b.m_intX=0;
>> }
>> for more info read Bruce Eckel thinking in c++ (http://www.mindview.com)
>> it's free.
>>
>>>
>>> Daniel
>>>
>>>
>>>
>
>
> Are you sure
>
>> class MyClass{
>> public :
>> MyClass (int x=0){
>> m_intX=x;
>> }
>> private:
>> m_intX;
>> }
>>
>> void main (void ){
>> MyClass a,b(10);
>> //a.m_intX=0 and in b.m_intX=0;
>> }
>
>
> is valid? MyClass (int x=0) is that valid
Have you ever heard about default parameters ?
> ? And when you pass 10 to the constructor, is it not expecting a
> variable of type int, not an integer?
it's OK code work except on bug * *int m_intX**
>
>
> _________________________________________________________________
> Unlimited Internet access -- and 2 months free! Try MSN.
> http://resourcecenter.msn.com/access/plans/2monthsfree.asp
>
>
>
> -------------------------------------------------------
> This sf.net emial is sponsored by: Influence the future of Java(TM)
> technology. Join the Java Community Process(SM) (JCP(SM)) program now.
> http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0002en
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--
Best Reagards Teodorescu Cristian Liviu (te...@xt...)
|