Declaring two objects of the same type in a function - C++ Class

C++ examples for Class:Member Function

Description

Declaring two objects of the same type in a function

Demo Code

#include <cstdlib> 
 #include <iostream> 

 using namespace std; 

 class MyClass /*  w  ww .j  av  a2 s. co m*/
 { 
 public : 
     int i; 
     float f; 
 }; 

 int main(int argc, char *argv []) 
 { 
     MyClass anObject, anotherObject; 

     anObject .i = 10; 
     anObject .f = 3.14159; 

     anotherObject .i = -10; 
     anotherObject .f = 0.123456; 

     cout << "anObject .i = " << anObject .i << endl; 
     cout << "anObject .f = " << anObject .f << endl; 

     cout << "anotherObject .i = " << anotherObject .i << endl; 
     cout << "anotherObject .f = " << anotherObject .f << endl; 

   
     return (0); 
}

Result


Related Tutorials