이 코드는 컴파일되지 않지만 코드에 무엇이 잘못되었는지 알 수 없습니다. 나는 shared_ptr
이 중요하다고 생각한다.순수 가상 기본 클래스와 shared_ptr을 사용하는 코드의 문제점
#include <memory>
#include <iostream>
using namespace std;
class A {
public:
virtual const void test() const = 0;
~A() { }
};
class AImpl : public A {
public:
const void test() const {
std::cout << "AImpl.test" << std::endl;
}
};
class B {
public:
B() { }
~B() {
}
shared_ptr<A> CreateA() {
a_ = make_shared<AImpl>(new AImpl());
return a_;
}
private:
shared_ptr<A> a_;
};
int main() {
B *b = new B();
shared_ptr<A> p = b->CreateA();
if (b) {
delete b;
b = NULL;
}
}
는 개발자를위한, 개발자, 개발자의 거룩한 구절을위한 컴파일러를 듣습니다. 컴파일러 출력은 무엇입니까? – PnotNP