C++构造函数初始化字符串字段,字段有顺序要求

class DCollection: public DMap {
public:

DCollection(std::string collectionName, DBClientConnection& conn,std::string dbName) :_collectionName(collectionName),_dbName(dbName),

             _conn(conn) {

    }


private:

    DCollection();

    std::string _collectionName;
    DBClientConnection& _conn;
    std::string _dbName;

};


像这样报错:

../src/db/config/../../memory/DCollection.h:154:14: warning: ‘memory::DCollection, memory::DSuper>::_dbName’ will be initialized after [-Wreorder]
../src/db/config/../../memory/DCollection.h:153:22: warning:   ‘mongo::DBClientConnection& memory::DCollection, memory::DSuper>::_conn’ [-Wreorder]
../src/db/config/../../memory/DCollection.h:33:2: warning:   when initialized here [-Wreorder]

这里说的是:_dbName字段不能在_conn字段后面,说得还很明白

解法办法就是,让他们换一下顺序:

private:

    DCollection();
    std::string _dbName;
    std::string _collectionName;
    DBClientConnection& _conn;
   

};

这估计是c++的关于有引用方面的要求


你可能感兴趣的:(C/C++技术专栏)