【发布时间】:2016-03-18 23:09:09
【问题描述】:
我有一个带有“已注册”类的向量列表。
main.cpp
// main.cpp:
// from namespace::class3
bool successfulregistered = RegisterComponents(vector<CustomNamespace::class1,CustomNamespace::class2>);
class3.h
// in class3
private:
vector<CustomNamespace> Objectinstance;
public:
bool RegisterComponents(vector<CustomNamespace>& RegisterComponents);
class3.cpp
// implementation
bool class3::RegisterComponents(vector<CustomNamespace>& RegisterComponents)
{
for(int i = 0; i < RegisterComponents.end(); i++)
{
class3::Objectinstance->iterator(*RegisterComponents);
// and then some checks
}
}
现在我喜欢收集对类的访问权限并创建对象实例来调用方法:
void class3::startserver(void)
{
for(auto i = Objectinstance.begin(); i != Objectinstance.end(); i++)
{
/* How can I create the objects from the vector list with
their classes and call the specific constructor? */
/* i == CustomNamespace::class1 */
}
}
class1.h
ConfigWatchdog(string &SetJSONFile, const char &cJSONRoot);
class2.h
ServerNetworking(unit& setIPAddress, ...);
【问题讨论】:
-
问题不清楚,代码看起来不像可编译的 C++(它混淆了迭代器和索引,使用
namespace作为类型名称等)请澄清您的问题并收紧代码以提供帮助我们回答这个问题。