upload
This commit is contained in:
31
CplusplusPractice/classtest.cc
Normal file
31
CplusplusPractice/classtest.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
|
||||
class A {
|
||||
int x;
|
||||
|
||||
public:
|
||||
A(int c) : x(c) {}
|
||||
A(const A &a) {
|
||||
x = a.x;
|
||||
std::cout << "복사 생성" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
class B {
|
||||
A a;
|
||||
|
||||
public:
|
||||
B(int c) : a(c) {}
|
||||
B(const B &b) : a(b.a) {}
|
||||
A get_A() {
|
||||
A temp(a);
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
B b(10);
|
||||
|
||||
std::cout << "---------" << std::endl;
|
||||
A a1 = b.get_A();
|
||||
}
|
||||
Reference in New Issue
Block a user