Networking, Programming and Graphics Tutorials

Pointers to objects - C++ [1/2]

Type:
Pointers to objects - C++
Level: Expert Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials Networking, Programming and Graphics Tutorials 
Pointers to objects - C++
Date: 2006-Dec-12
Pointers to objects - C++
Visited: 1915 times
Pointers to objects - C++
Rating: Pointers to objects - C++
Pointers to objects - C++
Author: Alex Plumpton

A pointer can point to an object of a class. Consider a class emp, which is defined as shown.

Example
Class emp
{
int code;
float salary;
public:
Void input(int cfloat s)
{
code=c
salary=s;
}
void display(void)
{
cout"EmpIoyee code'' code;
cout"
Employee salary "salary; 
}
};

we can declare a pointer ptr of type class emp

epm *ptr;
Pointer can be made to point to the object at runtime. Thus, they are useful for dynamic memory allocation. The pointer ptr of class emp is made to point to the address of the object objl as shown.

Emp *ptr = &obj1;

Obj1.input(5,2.3); 
Obj1.display();

(*
ptr).Obj1.input(5,2.3); (*ptr).0bj1.display();
Networking, Programming and Graphics Tutorials - Pointers to objects - C++ [1/2] - Networking, Programming and Graphics Tutorials

Need a specific tutorial? Do not hesitate and submit a request!
Related Tags: pointers to objects  pointers to objects-c++  c++-pointers to objects  c++ pointers to objects  c++ pointers objects  c++ "pointers to objects" tutorial  Parameterized objects inurl:Parameterized objects  array of objects-c++  end of file pointers C++  file pointers-c++  functions and pointers c++ * &  3d max objects crystals  c++ "file pointers" example  desktop objects C++  breaking objects in 3ds max  c++ arrays of objects   manipulation of pointers in C++  c++ array of objects  arrays of objects in C++  objects within array c++