Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISO C++ forbids declaration of 'vector' with no type

Tags:

c++

arduino

I am having an issue with arduino c and the StandardCplusplus package. 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: error: invalid use of '::'

Node.h:26: error: expected ';'before '<' token

Looking at other questions, here or here people forget the include or use std, but I have done both.

/*
 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.

edit2: I have removed everything except the vector as per comments yielding:

/*
 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.h:13: error: ISO C++ forbids declaration of 'vector' with no type

Node.h:13: error: invalid use of '::'

Node.h:13: error: expected ';' before '<' token

like image 953
Steven Stangle Avatar asked Oct 02 '22 18:10

Steven Stangle


2 Answers

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:

/*
 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
*/
#ifndef Node_h
#define Node_h

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

#endif
like image 165
lintmachine Avatar answered Oct 05 '22 12:10

lintmachine


Have you read the documentation? From http://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus ,

Can I use C++ on the AVR?

Basically yes, C++ is supported (assuming your compiler has been configured and compiled to support it, of course). Source files ending in .cc, .cpp or .C will automatically cause the compiler frontend to invoke the C++ compiler. Alternatively, the C++ compiler could be explicitly called by the name avr-c++.

However, there's currently no support for libstdc++, the standard support library needed for a complete C++ implementation. This imposes a number of restrictions on the C++ programs that can be compiled.

like image 44
David Hammen Avatar answered Oct 05 '22 11:10

David Hammen