我有以下代码:

#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct node{
    vector<int> vic;
    bool visitato = false;
};

int main (){
    vector<node> grafo;
    ifstream in("input.txt");
    int n, m, s, from, to;
    in >> n >> m >> s;
    grafo.resize(n);
    for (int i = 0; i < m; i++){
        in >> from >> to;
        grafo[from].vic.push_back(to);
    }
    for (int i = 0; i < grafo.size(); i++)
        for(int j = 0; j < grafo[i].vic.size(); j++)
            cout << "From node " << i << " to node " << grafo[i].vic[j] << endl;
}

并且(在Ubuntu上)我键入以下命令:
/usr/bin/g++ -DEVAL -static -O2 -o visita visita.cpp -std=c++0x

我收到以下错误:
visita.cpp:10:21: sorry, unimplemented: non-static data member initializers
visita.cpp:10:21: error: ISO C++ forbids in-class initialization of non-const static member ‘visitato’

在我家,它可以正常工作,但在大学里却不能。要执行的命令已由我们的老师发布。那为什么它在大学里不起作用,但在我家里呢?

最佳答案

GCC 4.7开始可用的非静态数据成员初始化程序。因此,请检查您的GCC版本。

10-08 00:48