Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Static Members - Advanced Programming - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Advanced Programming which includes Class Data Members, Class Data Initializers, Class Objects, Class Instructor, Constructor Initializer, User Defined Types, Appropriate Constructors, Class Declaration, Name of Base Class etc. Key important points are: Static Members, Data and Functions, Instantiated Objects, Static Data Members, Objects of Class, Declaration in Header File, Class Definition, Finite Number of Steps, Expressing Computer Algorithms

Typology: Slides

2012/2013

Uploaded on 03/21/2013

dharmaraaj
dharmaraaj 🇮🇳

4.4

(65)

153 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Classes
Static Members
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Static Members - Advanced Programming - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Classes

Static Members

Static Members

  • Data and Functions Can be static
  • Exists Independently of Any Instantiated Objects

Static Data Members -- Example

  • // student.h

#define size 20

class student{

char *name, *ss;

static char *instructor;

public:

student(char *, char *);

~student();

Static Data Members – Example (cont)

  • // student.cpp #include “student.h” #include student::student(char *ip_name, char ip_ss){ name = new char[size]; ss = new char[size]; strcpy(name, ip_name); strcpy(ss, ip_ss);} void student::print(){ cout << "Name: " << name << endl; cout << "SS: " << ss << endl; cout << "Instructor: " << instructor << endl;} }; / Definition and Initialization of Static member */ char *student::instructor = "Henry";

Static Member Functions

  • COMMON to All Objects of the Class
  • Created by the Class Definition -- Exist Even when NO Class Objects Exist
  • Can Only Access Static Data Members of the Class or other static member functions
  • Accessing -- class_name::function_name() or object_name.function_name()

Static Member Functions -- Example

  • // student.h #define size 20 class student{ char *name; char *ss; static char *instructor; public: student(char *ip_name, char *ip_ss); static void print_instructor(); };

Static Member Functions – Example (cont)

  • // client.cpp

#include “student.h”

main() {

student::print_instructor();

  • Output will be:

Notice that no instance of student is required.Instructor: Henry