Basics, object-oriented design

Access specifiers

public:

indicates that a member function or data member is accessible to other functions and member of other classes

private:

makes a data member or member function accessible only to member functions of the class; private is default access for class members

protected:

makes a data member function accessible to subclasses

Make 'set' and 'get' member functions to check and change private variables of a class. 'Set' function is better to have data validation.

Constructors

Functions used to initialize an object's data when it is created.

  • call made implicitly when object is created
  • must be defines with the same name as the class
  • cannot return values (not even void)

Default constructors have no parameters. The compiler will provide one when a class does not include a constructor itself. Compiler's default constructor implicitly calls constructors of data members that are objects of classes.

Use cascading while assigning values: var1 = var2 = var3 … = vark = value

Instead of if/else → value/value form we can use simpler form: (condition) ? if_ture : if_false

e.g.: x = (y>=100) ? "greater than 100" : "less than or equal to 100"

 
cpp/basics.txt · Последние изменения: 2009/09/28 01:51 От freetonik
 
За исключением случаев, когда указано иное, содержимое этой вики предоставляется на условиях следующей лицензии:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki