C++/Classes and Member declarations !
void add(int inum1,int inum2)
void sub(int inum1,int inum2)
i want to know the sequence in which prog executes.step by step pl.i get error when i declare ivar in public
Dear Mr Selva!
Before explaining the sequence let me explain the basic concepts in classes and member declaration that's because i found some bugs related to that !
>> int ivar=inum1;
Consider this statement , this is of course wrong in two way's
1. You cannot initialize a member just like we do with ordinary variable , ie the class member should be initialized either inside the member function or by using constructor .
Hope you have to change the statement just like this
>> int ivar , inum1; will be the correct form .
Then consider this statement :
You cannot access/use the class member ( ivar ) outside the class just what we do with normal variables , only provision given to access the class member is using the object of that class , so in order to print the value of ivar you have to use the following statement
cout<<var1.ivar; if you alter these statements sure you won't get error !
Execution sequence !
1.program starts with main()
2.object declaration ( star var1; )
once after declaring the object , it will try to execute the constructors , if present , but here in this program you didnt use any constructor .
3. Member ( public) functions are invoked using the class objects
4. And the final statement is a well known error , just no we discussed it
If you have any queries , please do follow up me !
Thanks and Regard!
Prince M. Premnath.