user2233131
user2233131

Reputation: 11

error: ISO C forbids declaration of `test' with no type

I'm learning C++ by myself and I ran into this problem. I wrote several lines of simple code just wanted to test "auto", and it seems that it no longer works. I pasted my code below:

#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    auto test=1;
    return 0;
}

Then the error in the title is reported. I use NetBeans IDE. Any advice would be appreciated.

Upvotes: 1

Views: 1178

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283891

The issue is that your compiler either doesn't support C++11 auto, or has it disabled (C++03 mode).

So the auto keyword, instead of meaning type inference, is a storage modifier. And then the type is missing.

Upvotes: 2

NPE
NPE

Reputation: 500903

To use the new C++11 meaning of auto, you have to have a compliant compiler, and tell it that the source file is using C++11 features.

With gcc, this is enabled using -std=c++11.

Upvotes: 0

Related Questions