c ++使用结构实例初始化构造函数

时间:2015-07-13 22:20:18

标签: c++ struct constructor instance

不知道如何将m_Performance放入get_Performance

$(document.body).on('click','.button', function(){

    // Find highlight-current, then get the next instance and make that one current

    $('.highlight-current').parent().nextAll(".live-search-highlight").eq(0).removeClass('live-search-highlight').addClass('highlight-current');

    // Reset the previous one so it's no longer current

    $('.highlight-current:first').removeClass('highlight-current').addClass('live-search-highlight');

});

创建结构

struct Performance
{
    double High;
    double Average;
    double Low;
}Perf;

创建课程&插入方法get_Performance。出了点问题。

class Strategy
{ public:
Performance m_Performance(){
    Perf.High = 10.1;
    Perf.Average =5.1;
    Perf.Low =1.1;
};
void get_Performance(){
    m_Performance();     ///This part does not work
}
};

想从结构中获取数据成员

1 个答案:

答案 0 :(得分:0)

如果我理解正确,你应该:

struct Performance
{
    double High;
    double Average;
    double Low;
};

class Strategy
{ 
private:
    Performance m_Performance;
public:
    Strategy() {
        m_Performance.High = 10.1;
        m_Performance.Average = 5.1;
        m_Performance.Low = 1.1;
    }
    Performance get_Performance() {
       return m_Performance;
    }
};

int _tmain(int argc, _TCHAR* argv[])
{
    Strategy a;
    Performance p = a.get_Performance();
    return 0;
}
相关问题