Error: 'I' Does Not Name a Type with Auto

Error: does not name a type (using auto)

I run the example without --std=c++11, it fails with the same error message.

Try to configure codeblocks again like this suggests.

Or you can run the code by hand like g++ --std=c++11 code.cc.

To see if C++11 is enabled, you can type more C++11 code, like just declaring nested vector vector<vector<int>> vv; to see if it deals >> well.


  1. How can I add C++11 support to Code::Blocks compiler?

error using auto: does not name a type, c++ version of numpy's arange

As @Brian suggested, I had not enabled C++11 support.

$ c++ --version
c++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This fails:

$ c++ test_arange_c.cpp -o test_arange_c.out
test_arange_c.cpp: In function ‘int main()’:
test_arange_c.cpp:16:8: error: ‘t_array’ does not name a type
auto t_array = arange<double>(0, 40, dt);
^

This works:

$ c++ -std=c++11 test_arange_c.cpp -o test_arange_c.out
$

error: ‘i’ does not name a type

GCC doesn't enable C++11 mode automatically, and for type-deduction using auto you need C++11 mode (or later).

You can enable this with the -std=c++11 option:


$ g++ -std=c++11 your_source_file.cpp

Does not name a type C++

First thing I notice:

#include <iterator>

Is nowhere to be found. It should be in tag_remover.cc

std::istream_iterator<>

Is defined in… <iterator>

Also the TagRemover default constructor seems to be declared but not defined.

Furthermore, you can define TagRemover::TagRemover(std::istream&) like this:

TagRemover::TagRemover(std::istream& in) 
: str{ [] (auto& is) {
std::skipws(is); // ignore spaces
using iser = std::istream_iterator<char>;
return std::string(iser(is), iser());
}(in) }
{}

c++ auto does not name a type

The boost headers aren't getting picked up for the same reason the Qt headers wouldn't unless you specify -I /usr/include/QtCore/. There is nothing special about the boost headers for the compiler to be partial towards them. The Search Path section of GCC's documentation may help you.

X does not name a type error in C++

When the compiler compiles the class User and gets to the MyMessageBox line, MyMessageBox has not yet been defined. The compiler has no idea MyMessageBox exists, so cannot understand the meaning of your class member.

You need to make sure MyMessageBox is defined before you use it as a member. This is solved by reversing the definition order. However, you have a cyclic dependency: if you move MyMessageBox above User, then in the definition of MyMessageBox the name User won't be defined!

What you can do is forward declare User; that is, declare it but don't define it. During compilation, a type that is declared but not defined is called an incomplete type.
Consider the simpler example:

struct foo; // foo is *declared* to be a struct, but that struct is not yet defined

struct bar
{
// this is okay, it's just a pointer;
// we can point to something without knowing how that something is defined
foo* fp;

// likewise, we can form a reference to it
void some_func(foo& fr);

// but this would be an error, as before, because it requires a definition
/* foo fooMember; */
};

struct foo // okay, now define foo!
{
int fooInt;
double fooDouble;
};

void bar::some_func(foo& fr)
{
// now that foo is defined, we can read that reference:
fr.fooInt = 111605;
fr.foDouble = 123.456;
}

By forward declaring User, MyMessageBox can still form a pointer or reference to it:

class User; // let the compiler know such a class will be defined

class MyMessageBox
{
public:
// this is ok, no definitions needed yet for User (or Message)
void sendMessage(Message *msg, User *recvr);

Message receiveMessage();
vector<Message>* dataMessageList;
};

class User
{
public:
// also ok, since it's now defined
MyMessageBox dataMsgBox;
};

You cannot do this the other way around: as mentioned, a class member needs to have a definition. (The reason is that the compiler needs to know how much memory User takes up, and to know that it needs to know the size of its members.) If you were to say:

class MyMessageBox;

class User
{
public:
// size not available! it's an incomplete type
MyMessageBox dataMsgBox;
};

It wouldn't work, since it doesn't know the size yet.


On a side note, this function:

 void sendMessage(Message *msg, User *recvr);

Probably shouldn't take either of those by pointer. You can't send a message without a message, nor can you send a message without a user to send it to. And both of those situations are expressible by passing null as an argument to either parameter (null is a perfectly valid pointer value!)

Rather, use a reference (possibly const):

 void sendMessage(const Message& msg, User& recvr);

Does not name a type

Now I'm assuming you wrote the code exactly as specified:

struct node *nodes[1024];
nodes[1]->data = 1;
nodes[1]->left = NULL;
nodes[1]->right = NULL;

The reason you are getting compiler errors is because that is not valid C++ code.

But if you move that code into a function it will compile just fine:

struct node *nodes[1024];

void AddFunction()
{
nodes[1]->data = 1;
nodes[1]->left = NULL;
nodes[1]->right = NULL;
}


Related Topics



Leave a reply



Submit