in Education by
I'm trying to create two dimensional std::vector, that will hold objects of this class I inherited. The problem I have is that this class has only one constructor, and that uses one parameter (std::string to be precise). #define HEIGHT 4 #define WIDTH 4 #include using std::vector; static vector > reaper(HEIGHT, vector (WIDTH)); This should create 4x4 matrix of Reaper objects in my vector. At least I know it would work if I had constructor with no parameters available. But, this is how I would instantiate Reaper object: Reaper r0("R0"); Reaper* r1 = new Reaper("R1"); Now, I can't figure out how to include this constructor into my vector construction? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use the vector(size_t n, const T& t) constructor to initialize the inner vector of reapers to some initial constant value, like static vector > reaper(HEIGHT, vector (WIDTH, Reaper("value"))); You seem to use this once for the outer vector --- you can use it for the inner vector as well. Alternately, you can create a 2d-vector of pointers to reapers.

Related questions

0 votes
    I have a vector of numbers: numbers...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have a huge vector which has a couple of NA values, and I'm trying to find the max value in that vector ( ... I can compute the max? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    How can I check if a given value is contained in a vector? Select the correct answer from above options...
asked Jan 20, 2022 in Education by JackTerrance
0 votes
    If two vectors with different lengths perform some operation, the elements of the shorter vector will be used ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I have a struct X with two 64-bit integer members, and a constructor: struct X { X(uint64_t a, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    When I do this: std::vector hello; Everything works great. However, when I make it a vector of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    The code below copies data from one vector into another. If the vectors are large then I guess this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    The code below copies data from one vector into another. If the vectors are large then I guess this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Generic iterator (3 answers) Closed 7 years ago. Suppose I want to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
...