bog
bog

Reputation: 1323

C++: unimplemented: non-static data member initializers

I have the following code:

#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;
}

And (on Ubuntu) I type the following command:

/usr/bin/g++ -DEVAL -static -O2 -o visita visita.cpp -std=c++0x

And I get the following error:

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’

At my home it works fine but here in the university it doesn't. The command to executed has been posted by our teacher. Then why doesn't it work in the uni but it does in my home?

Upvotes: 1

Views: 3532

Answers (2)

bog
bog

Reputation: 1323

Solved with this code:

struct node{
    vector<int> vic;
    bool visitato;
    node() : visitato(false) {}    
};

Upvotes: 2

zaufi
zaufi

Reputation: 7129

Non static data member initializers available since GCC 4.7. So, check your GCC version.

Upvotes: 5

Related Questions