如果父级没有没有参数的构造函数,我该如何创建子构造函数
How can I make child constructor if parent doesn't have constructor without params
我有一个库,我不能用父 class:
class A {
public:
A(immpl i) { /* do smth */ }
}
我要写子-class:
class B : public A {
public:
B(FSImplPtr impl) : A(impl) {};
};
一切正常。所以我可以通过以下方式创建 child-class:
B(SomeFunction(new VFSImpl()));
所以,我想创建没有参数的构造函数,就像这样:
class B : public A {
public:
B() : A(SomeFunction(new VFSImpl())) {};
};
但是当我尝试时 - 我有一个错误:
error: expected primary-expression before '(' token
B() : A(FSImplPtr(new VFSImpl())) {}
^
error: expected type-specifier before 'VFSImpl'
B() : A(FSImplPtr(new VFSImpl())) {}
^
我该如何解决?
VFSImpl 存在吗?我没有在 git 文件中看到它。我认为这是一个拼写错误,您需要 FSImpl。
我有一个库,我不能用父 class:
class A {
public:
A(immpl i) { /* do smth */ }
}
我要写子-class:
class B : public A {
public:
B(FSImplPtr impl) : A(impl) {};
};
一切正常。所以我可以通过以下方式创建 child-class:
B(SomeFunction(new VFSImpl()));
所以,我想创建没有参数的构造函数,就像这样:
class B : public A {
public:
B() : A(SomeFunction(new VFSImpl())) {};
};
但是当我尝试时 - 我有一个错误:
error: expected primary-expression before '(' token
B() : A(FSImplPtr(new VFSImpl())) {}
^
error: expected type-specifier before 'VFSImpl'
B() : A(FSImplPtr(new VFSImpl())) {}
^
我该如何解决?
VFSImpl 存在吗?我没有在 git 文件中看到它。我认为这是一个拼写错误,您需要 FSImpl。