C++ Lecture 2 - C Lecture 2...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Lecture 2 http://www.cs.mun.ca/~gstarkes/3710/c++/lecture2.html 1 of 7 4/13/2009 5:25 PM C++ Lecture 2 [Previous Lecture] [Lecture Index] [Next Lecture] Intro to C++ Classes a class is an `enhanced' structure like a C structure, it has data fields; also called instance variables data members member variables ( instance means an actual copy of a class) can specify `functions' that manipulate the class These `functions' are referred to as: methods instance methods member functions Instance Methods functions that are called to operate on a particular instance of a class a pointer to the class is implicitly passed to instance methods an instance method is called using the syntax var_name.method_name(/* parameters */); where varname is an instance of a class inside the method, instance variables and methods of the class are `in scope' Access Control public: allows things outside the class to access the following entities private: prevents things outside the class from accessing the following entities class xyz starts in `private mode' struct xyz starts in `public mode' class Xyz { int a; // private by default public: int b; int foo() { return a + b + c + bar(); } private: int c; int bar() { return a * b * c; } };
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ Lecture 2 http://www.cs.mun.ca/~gstarkes/3710/c++/lecture2.html 2 of 7 4/13/2009 5:25 PM int test() { Xyz x; return x.b + x.foo() // ok + x.a // NOT allowed + x.c // NOT allowed + x.bar(); // NOT allowed } Creating Header Files Header files typically contain: symbolic constants type definitions function prototypes global variable declarations General form of header file: #ifndef FILENAME_H # define FILENAME_H // Declaration of simple types // Definition of symbolic constants // Forward declaration of classes # include "others.h" // Definition of classes // Global variables
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/24/2009 for the course PROGRAMMIN C++ Progra taught by Professor Showman during the Spring '09 term at Zagazig University.

Page1 / 8

C++ Lecture 2 - C Lecture 2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online