C++:错误:预期';' 在声明列表的末尾(用clang ++ 3.4编译)

han*_*jin -1 c++ c++11 clang++

我试着写一个非常简单的进度条类.我将所有内容放入progressBar.h中,并创建了一个最小的测试用例.我在Ubuntu 14.04上使用clang ++ 3.4运行它.我包括-std = c ++ 11标志.测试用例创建了一个新的ProgressBar对象并调用成员函数displayProgress(double).我包括在ProgressBar.h中.

这是我的代码:

#include <ostream>
#include <string>

class ProgressBar
{
private:
    std::ostream& out;
    int width;

public:
    ProgressBar(std::ostream& out, int _width = 80)?out(out) {
        width = _width - 9;
    }

    void displayProgress(double percentage) {
        out << "\r[" << fixed << setprecision(2) << percentage * 100 << "%]";
        for (int i = 0; i < width * percentage; ++i) out << "=";
        if (percentage != 1) out << ">";
        else out << "O";
    }
};
Run Code Online (Sandbox Code Playgroud)

这是错误消息:

In file included from test.cpp:2:
./progressBar.h:11:52: error: expected ';' at end of declaration list
    ProgressBar(std::ostream& out, int _width = 80)?out(out) {
                                                   ^
                                                   ;
test.cpp:8:4: error: no member named 'displayProgress' in 'ProgressBar'
        p.displayProgress(0.5);
        ~ ^
2 errors generated.
Run Code Online (Sandbox Code Playgroud)

Cor*_*lks 13

?不是:.你在代码中得到的是一个完整的COLON,而不仅仅是一个COLON.

替换?:.