I want to create a class but I am not sure if I am declaring an array correctly in a class.
my header file
#ifndef SOMECLASS_H
#define SOMECLASS_H
#include <string>
class MyClass {
public:
MyClass();
~MyClass();
private:
std:string myStringArray[];
int myIntegerArray[];
};
#endif SOMECLASS_H
my class file
#include "someClass.h"
MyClass::MyClass() {
std::string myStringArray[] = {"Option1","Option2",
"Option3","Option4"};
int myIntegerArray[] = {1,2,3,4};
}
But that doesn't seem to work... I want to initialize the array when the class is created. Can someone please explain to me what I am doing wrong. Thank you.
std::vector. Otherwise read aboutstd::array. You also want to read about member initializer lists.