Commit 5c21d5ab authored by BRENO RILHO LEMOS's avatar BRENO RILHO LEMOS

Accessing object's members through pointers

parent 492279e8
#include <iostream>
using namespace std;
class breno {
int b;
public:
breno(int n);
int getb();
};
breno::breno(int n) {
b = n;
}
int breno::getb(){
return b;
}
int main() {
breno b1(1);
breno *pb1 = &b1; // pointer that contains address of b1
cout << "Integer using pointer: " << pb1->getb();
cout << "\nInteger using object: " << b1.getb();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment