C++错误:预期'{'

im_*_*chc 0 c++

救命!我是C++的新手......如何修复此头文件?

#pragma once
class MyCls2
{
private:
    int _i, _j;
public:
    MyCls2(int i, int j) : _i(i), 
                            _j(j)
    MyCls2(); // error: expected a '{'
    ~MyCls2(void);
};
Run Code Online (Sandbox Code Playgroud)

这是MS VC 2010中的错误:

错误:预期'{'


谢谢你的帮助,我得到了我现在想要的东西:

.H:

#pragma once
class MyCls2
{
private:
    int _i, _j;
public:
    MyCls2(int i, int j) ;
    MyCls2();
    ~MyCls2(void);
};
Run Code Online (Sandbox Code Playgroud)

的.cpp:

#include "StdAfx.h"
#include "MyCls2.h"


MyCls2::MyCls2()
{
}

MyCls2::MyCls2(int i, int j) : _i(i), 
    _j(j)
{
}
MyCls2::~MyCls2(void)
{
}
Run Code Online (Sandbox Code Playgroud)

Mah*_*esh 5

您正在使用初始化列表提供构造函数定义.因此,它需要{}像任何其他(成员)功能一样.

MyCls2(int i, int j) : _i(i), 
                       _j(j) {} // Missing the opening and closing braces
Run Code Online (Sandbox Code Playgroud)