Defining a object with a C++ class - C++ Class

C++ examples for Class:Class Creation

Description

Defining a object with a C++ class

Demo Code

#include <cstdlib> 
 #include <iostream> 

 using namespace std; 

class MyClass /*from  w  ww.  j  a  va  2 s  .  c o m*/
 { 
 public : 
     int i; 
     float f; 
}; 

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

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

     cout << "i = " << anObject .i << endl; 
     cout << "f = " << anObject .f << endl; 
   
     return (0); 
}

Result


Related Tutorials