初始化类

初始化类

问题描述:

我想初始化类初始化类

const int count = 5; 

class In 
{ 
    float rate; 
public: 
    In(int index) 
    { 
     rate = index/count; 
    } 
}; 

class Out 
{ 
    In ins[count]; 

public: 
    Out() : /* ??? */ 
    { 
    } 
}; 

我可以在初始化插件获得的实例的指标,如果我将依靠数组的类成员的数组的类成员初始化列表Out::Out()

+2

你能更清楚地解释你的要求吗? – MARK 2012-02-22 15:50:22

+0

@Raza我想他想在初始化列表中初始化数组。 – 2012-02-22 16:01:05

你不能那样做。您需要为In定义默认构造函数。

或更好的是,使用std::vector

编辑:可能在C + + 11支持,但不知道。