这是我的班级结构
class A
{
public:
void doSomething {
bInstance -> bMethod();
}
...
private:
std::shared_ptr<B> bInstance
}
class B
{
public:
void bMethod();
}
A::A(std::shared_ptr<B> bInstance)
: bInstance(bInstance){}
然后使用GTest,这是我的测试夹具
// Test Fixture
class ATest: public ::testing::Test {
protected:
ATest()
: bInstancePointer(std::make_shared(...)),
aInstance(bInstancePointer)
{}
A aInstance;
std::shared_pt bInstancePointer;
};
在我的测试中我有
aInstance.doSomething()
这会导致分段错误。是否有人知道此语法不正确的原因,或者对如何重新构造指针的初始化以避免此分段错误有任何建议?