| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Class Fundamentals

Page history last edited by Lucas Wojciechowski 15 years, 4 months ago

Classes

  • Template to define the form of an object
  • Specifies both code and data, functions and varibles.

class classname{

     int privatedata;

     int privatefunction();

     public:

     int publicdata;

     int publicfunction;

}


 

Private/Public

  • By default, any function or varible will be private
  • Everything after the "public:" command is public

 

Accessing Varibles & Functions


classname.publicdata = 5;

classname.publicfunction();


 

Functions in Classes

  • Functions must be declared in the desired secion of the class (public or private)
  • Scope operater is used to tell the program which function belongs to which class.
    • Scope operator is "::"

int classname::publicfunction() {

     ...

}


 

Constructor

  • Code to be run when the class is initalized. The destructor runs when the class is destroyed (eg. program terminates)

class classname{

     classname();    //Constructor

     ~classname();   //Destructor

}


 

Paramterized Constuctors

  • Parameters can be passed to construcors the same way as any other function.

class classname{

     classname(int data);

}

classname::classname(int data){

     ...

}

classname object(5);


 

Comments (0)

You don't have permission to comment on this page.