+ 1
Can you give a programme for pointers to objects
2 Respuestas
+ 2
Here is c++ source for a program with pointers to objects. It has a pointer to an int and a pointer to an instance of a class which is also known as an object.
#include <iostream>
using namespace std;
class Point {
public:
int z=0;
};
int main() {
int x = 5;
int * y = &x;
// y is a pointer.
// y has the address of x.
// In other words, y is a pointer to x.
cout << (*y) << endl;
Point p; // instance of a class.
p.z=3;
Point * objectPointerToP = &p;
cout << "z = " << (objectPointerToP->z);
return 0;
}