View Single Post
Join Date: Apr 2008
Posts: 59
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 1
chunalt787 chunalt787 is offline Offline
Junior Poster in Training

setting size of 2-D array at constructor issue

 
0
  #1
Nov 24th, 2008
I am trying to pass the size of the matrix array during the constructor but its giving me the following error. Is there a different way to do this?

  1. In file included from Main.cpp:1:
  2. AdjacencyMatrix.h: In constructor ‘AdjacencyMatrix::AdjacencyMatrix(int, std::string)’:
  3. AdjacencyMatrix.h:13: error: ‘numberOfNodes’ cannot appear in a constant-expression
Line 13 is the constructor declaration.

Here is my code
  1. #include<string>
  2. #include<fstream>
  3.  
  4. using namespace std;
  5.  
  6. class AdjacencyMatrix {
  7. private:
  8. bool* matrix;
  9. public:
  10. AdjacencyMatrix(int const numberOfNodes, string fileName)
  11. {
  12. matrix = new bool[numberOfNodes[numberOfNodes]; //two dimensional array
  13. populateArray(fileName);
  14. }
  15. void populateArray(string filName);
  16. };

Thanks in advance
Reply With Quote