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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With