简体   繁体   English

ISO C ++禁止声明无类型的“向量”

[英]ISO C++ forbids declaration of 'vector' with no type

I am having an issue with arduino c and the StandardCplusplus package. 我在使用arduino c和StandardCplusplus软件包时遇到问题。 I am trying to declare a vector but get the following error: 我正在尝试声明一个向量,但出现以下错误:

Node.h:26: error: ISO C++ forbids declaration of 'vector' with no type Node.h:26:错误:ISO C ++禁止声明无类型的“向量”

Node.h:26: error: invalid use of '::' Node.h:26:错误:无效使用'::'

Node.h:26: error: expected ';'before '<' token Node.h:26:错误:预期';'在'<'标记之前

Looking at other questions, here or here people forget the include or use std, but I have done both. 在其他问题上,人们在这里这里忘记了include或use std,但是我都做到了。

/*
 Node.h
*/
#ifndef Node_h
#define Node_h
#include "Arduino.h"
#include <StandardCplusplus.h>
#include <vector>
#include <string>
#include <iterator>
class Node
{
  public:
    Node(int size);
    ~Node();
    float bias();
    void set_bias(float);
    void print();
    void fprint(FILE *);
    float compute(std::vector<float> inputs);
    void setWeights(std::vector<float> inws);
    void set_weight(int,float);
    float dutyCycle();

  protected:
    std::vector<float> _weights;               //input weights:30
    float level;
    void init(int size);
    std::vector<int> firelog;

};

#endif

thanks 谢谢

edit: I am using the arduino 1.5.5 ide compiler. 编辑:我正在使用arduino 1.5.5 ide编译器。

edit2: I have removed everything except the vector as per comments yielding: edit2:我删除了除矢量以外的所有内容,按注释产生:

/*
 Node.h
*/
#ifndef Node_h
#define Node_h

#include <vector>
class Node
{
  public:
      Node();
      ~Node();
      std::vector<int> test;
};

#endif

which still outputs the error: 仍然输出错误:

In file included from Node.cpp:1: 在Node.cpp包含的文件中:1:

Node.h:13: error: ISO C++ forbids declaration of 'vector' with no type Node.h:13:错误:ISO C ++禁止声明无类型的“向量”

Node.h:13: error: invalid use of '::' Node.h:13:错误:无效使用'::'

Node.h:13: error: expected ';' Node.h:13:错误:预期为';' before '<' token 在“ <”令牌之前

I just ran into this same issue and was able to resolve it by including StandardCplusplus.h in my main sketch .ino file, rather than in the C++ class header file that I wanted to use the vector in. So, it looks roughly like this: 我遇到了同样的问题,并且能够通过在我的主要草图.ino文件中包含StandardCplusplus.h来解决此问题,而不是在要使用该向量的C ++类头文件中包含它。因此,它看起来大致像这样:

/*
 Main.ino (or whatever your main sketch file is called)
*/

#include <StandardCplusplus.h>
#include "Node.h"

// ...

void setup()
{
}

void loop()
{
}

Then in Node.h: 然后在Node.h中:

/*
 Node.h
*/
#ifndef Node_h
#define Node_h

#include <vector>
class Node
{
  public:
      Node();
      ~Node();
      std::vector<int> test;
};

#endif

Have you read the documentation? 您阅读过文档吗? From http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus , http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus

Can I use C++ on the AVR? 我可以在AVR上使用C ++吗?

Basically yes, C++ is supported (assuming your compiler has been configured and compiled to support it, of course). 基本上可以,C ++受支持(当然,假设您的编译器已配置并编译为支持它)。 Source files ending in .cc, .cpp or .C will automatically cause the compiler frontend to invoke the C++ compiler. 以.cc,.cpp或.C结尾的源文件将自动导致编译器前端调用C ++编译器。 Alternatively, the C++ compiler could be explicitly called by the name avr-c++. 或者,可以使用名称avr-c ++显式调用C ++编译器。

However, there's currently no support for libstdc++, the standard support library needed for a complete C++ implementation. 但是,目前不支持libstdc ++,这是完整C ++实现所需的标准支持库。 This imposes a number of restrictions on the C++ programs that can be compiled. 这对可以编译的C ++程序施加了许多限制。

Preprocess the file using the -E option of the compiler and removing stuff the compiler will complain about like -c and -o . 使用编译器的-E选项预处理文件,并删除编译器会抱怨的东西-c-o Since you don't show how you try to compile the code it is impossible to advise how the invocation should look exactly. 由于您没有显示如何尝试编译代码,因此无法建议调用的外观。 Note, that the output is bound to be large, ie, you should redirect it either to a file or pipe it to something like less . 注意,输出必然很大,即,您应该将其重定向到文件或通过管道传递给less

Once the file is processed, check that the declarations in the Node class still read something like the original (what exactly the result will look like depends on the compiler). 处理完文件后,检查Node类中的声明是否仍读取原始内容(确切的结果取决于编译器)。 In particular verify that the std isn't magically gone ( 特别要确认std没有神奇消失(

If the line looks OK check that the <vector> header got properly included. 如果该行看起来不错,请检查是否正确包含了<vector>标头。 You should be able to fine a line match #.*vector which, eg, looks like this in the preprocessed output on my machine: 您应该能够对行匹配#.*vector进行细化,例如,在我的机器的预处理输出中看起来像这样:

# 1 "/opt/gcc-current/include/c++/4.9.0/vector" 1 3

After that line you'd expect actual declaration of the std::vector template (well, at some point; it may include other headers first). 在那行之后,您应该期望std::vector模板的实际声明(嗯,在某些时候;它可能首先包含其他标头)。 If the compiler find a different file which happens to be called vector the declarations of std::vector may have gone missing. 如果编译器找到另一个文件,该文件恰好被称为vector ,则std::vector的声明可能会丢失。

Another candidate may be something defining the include guard for the <vector> header. 另一个候选者可能是为<vector>标头定义包含保护的对象。 That would be before the code of the vector file whose location was found above. 那将在上面找到其位置的vector文件的代码之前。 For example, the file /opt/gcc-current/include/c++/4.9.0/vector uses _GLIBCXX_VECTOR as include guard which is unlikely to be defined but I don't know what your headers are doing. 例如,文件/opt/gcc-current/include/c++/4.9.0/vector使用_GLIBCXX_VECTOR作为包含保护,不太可能定义,但我不知道您的标头在做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM