You look like you're probably a java/C# programmer. You don't need to put public: before every public function. Here's what you meant to put I believe. I renamed some variables just because I didn't understand which one was x and which one was y.
Notice the super weird syntax on the constructor. when you want to make a vector of a certain size the constructor to use is:
vector<T>(n, T());
so when you want a 20x20 vector of vectors of T() you have to say:
1 2 3
vector<vector<T>> (20,
vector<T>(20, T())
);
which can be confusing but basically you're creating a vector<T> of size 20 using the T() constructor. Then you do that 20 times for a vector<vector<T>>.
#include <iostream>
#include <sstream>
#include <vector>
usingnamespace std; //just do this if you intend to only use std objects and functions
constint X = 20;
constint Y = 20;
class TestMap {
//private:
struct MyTestStruct {
string testString;
};
vector<vector<MyTestStruct>> myTestVector;
public:
TestMap() : myTestVector (vector<vector<MyTestStruct>>(X, vector<MyTestStruct>(Y, MyTestStruct()))) {}
void setTestSumm (const string& newSumm, int x, int y) { //const string& if not modifying
myTestVector.at(x).at(y).testString = newSumm; //use .at() for range checking
}
string getTestSumm (int x, int y) const { //put const if you don't modify member variables
return myTestVector.at(x).at(y).testString;
}
};
int main() {
string input;
string place;
int inputX = 0;
int inputY = 0;
TestMap mapTest;
cout << "Enter a short place description:\n";
getline(cin, place);
cout << "Enter a number between 0 and 19:\n";
getline(cin, input);
stringstream(input) >> inputX;
cout << "Enter another number between 0 and 19\n";
geline(cin, input);
stringstream(input) >> inputY;
mapTest.setTestSumm(place, inputX, inputY);
cout << "Summary: " << mapTest.getTestSumm(inputX, inputY) << "\n";
}
I hope this helps! you may want to go look up STL templated constructors?
Ah, ok, I see now. Yeah definitely need to brush up on my constructors (and much else), I'm jumping back into c++ after first dabbling in it about 6-7 years ago. And yeah, definitely more familiar with Java. Thank you much, problem solved!