鉴于我有:
A
int
的构造函数,它带有B
参数A
的子类,它继承自B
int
的成员变量A
,名为A::A(int)
如何在B
的构造函数中调用构造函数A
?似乎我所能做的就是初始化名为#include <iostream>
class A
{
public:
A();
A(int);
};
class B : public A
{
public:
B();
int A = 100;
};
A::A()
{
std::cout << "in constructor A";
}
A::A(int s)
{
std::cout << "value in A constructor " << s;
}
// Here I want to initialize the base class with 50
// and the member with 78. Is it possible?
B::B() : A(50), A(78)
{
std::cout << "in Constructor B";
std::cout << A;
}
int main()
{
B b;
}
的成员变量。
她是一个重现这个问题的简短代码:
B::B() : A(50)
{
A = 78;
std::cout << "in Constructor B";
std::cout << A;
}
我想用78初始化类成员A,并用50调用基类构造函数。我该怎么做?
如果我尝试分配给会员:
in constructor Ain Constructor B78
输出
A::A(int)
它没有调用// Inside your [AppDelegate didFinishLaunchingWithOptions:]
RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
config.schemaVersion = 1;
// Set the block which will be called automatically when opening a Realm with a
// schema version lower than the one set above
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) {
// We haven’t migrated anything yet, so oldSchemaVersion == 0
if (oldSchemaVersion < 1) {
// Nothing to do!
// Realm will automatically detect new properties and removed properties
// And will update the schema on disk automatically
}
};
// Tell Realm to use this new configuration object for the default Realm
[RLMRealmConfiguration setDefaultConfiguration:config];
// Now that we've told Realm how to handle the schema change, opening the file
// will automatically perform the migration
[RLMRealm defaultRealm];
重载的构造函数。