Skip to content

Commit

Permalink
OOP access to private area
Browse files Browse the repository at this point in the history
  • Loading branch information
redtree0 committed Feb 13, 2019
1 parent 9bdfbcb commit 610f42d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions OOP/src/accessToAddress_privateArea.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// main.cpp
// practice
//
// Created by 김천규 on 12/02/2019.
// Copyright © 2019 김천규. All rights reserved.
//

#include <iostream>
#include <string>

using namespace std;

class Test {
private :
int hidden;
public :
int opened;
Test(int val);
};

Test::Test(int val) {
hidden = val;
// cout << &hidden << endl;
}

int main(int argc, const char * argv[]) {

Test *test = new Test(100);

cout << "-------- 값 --------" << endl;
test->opened = 20;
// cout << test->hidden << endl; //'hidden' is a private member of 'Test'
cout << "test member variable hidden value"<< *(&test->opened -1) << endl;
cout << "test member variable opened value" << test->opened << endl;

cout << "-------- 주소 --------" << endl;
cout << "test instance address : "<< &test << endl;
cout << "test member variable hidden address : " << (&test->opened -1)<< endl;
cout << "test member variable opened address : " << &test->opened << endl;

delete test;
return 0;
}

0 comments on commit 610f42d

Please sign in to comment.