I'm trying to do something like that:
//stack.h
#ifndef STACK_H_INCLUDED
#define STACK_H_INCLUDED
#include <vector>
struct CharStack {
int sp;
std::vector<char> data(87);
} S;
But I get some errors like:
error: expected identifier before numeric constant
error: expected ',' or '...' before numeric constant
Why does that happen? There seems to be no problem when I want to create a vector with dynamic length
To construct objects in a struct (or class) you need to write a constructor. Like this
struct CharStack {
CharStack() : data(87) {}
int sp;
std::vector<char> data;
} S;
It's just how C++ syntax is.
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