I have to create a small gui project using Visual Studio 2012 forms, the major problem: I can't create an array of objects for my life, not even the fellow students' projects run.
array<className^>^ arrayName = gcnew array<className^>(100);
Or in my case:
array<kind^> ^testArray = gcnew array<kind^>(100);
should be working. Should. The error is somewhat like
Error: data member initializer is not allowed
It works for others but somehow not for me in vs2012, even though it's exactly the same. Don't get what I'm missing.
Quick and dirty example of a classes.h I created to test stuff:
ref class memberino {
private:
String^ memVar;
public:
memberino(){};
memberino(String^ memVar_);
String^ getMemVar() { return memVar; }
void setMemVar(String^ memVar_) { this->memVar = memVar_; }
};
ref class baseClass abstract {
private:
String^ baseVar;
memberino M;
public:
baseClass(){};
baseClass(String^ baseVar_, String^ memVar_);
virtual String^ getMemVar() { return M.getMemVar(); }
virtual String^ getBaseVar() { return baseVar; }
virtual void setBaseVar(String^ baseVar_) { this->baseVar = baseVar_; }
virtual String^ getChildVar() = 0;
};
ref class kind: public baseClass {
private:
String^ childVar;
public:
kind(){};
kind(String^ baseVar_, String^ memVar_, String^ childVar_);
virtual String^ getChildVar() override { return childVar; }
virtual void setChildVar(String^ childVar_) { this->childVar = childVar_; }
};
And the classes.cpp:
memberino::memberino(String^ memVar_){
this->setMemVar(memVar_);
}
baseClass::baseClass(String^ baseVar_, String^ memVar_):M(memVar_){
this->setBaseVar(baseVar_);
}
kind::kind(String^ baseVar_, String^ memVar_, String^ childVar_):
baseClass(baseVar_, memVar_){
this->setChildVar(childVar_);
}
In the MyForm.h I just try to create an array like:
array<kind^> ^testArray = gcnew array<kind^>(100);
Before trying to run it it's red underlined with the error mentioned above. Compiling it gives following output:
warning C4677: "testArray": The signature of the non-private member includes the private assemblytype "kind".
error C3845: "pr5temp::MyForm::testArray": Only static data members can be initialized in a reference class or value type
Not 100% as it's a translation from German to english, but in case it helps:
warning C4677: "testArray": Die Signatur des nicht privaten Members enthält den privaten Assemblytyp "kind".
error C3845: "pr5temp::MyForm::testArray": Nur statische Datenmember können innerhalb einer Verweisklasse oder eines Werttyps initialisiert werden.