setting size of 2-D array at constructor issue

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2008
Posts: 60
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 Quick reply to this message  
Join Date: Aug 2007
Posts: 1,673
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: setting size of 2-D array at constructor issue

 
0
  #2
Nov 24th, 2008
I find that it compiles fine, after you take the excess [numberOfNodes .

I would think that removing the const keyword from your parameter list would clear the error you're getting.

FYI, you're not declaring or allocating a 2D array. bool* matrix; will be a 1D array only.

(using VC++ 2005)
"We Americans got so tired of being thought of as dumb by the rest of the world that we went to the polls last November and removed all doubt."
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 60
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 1
chunalt787 chunalt787 is offline Offline
Junior Poster in Training

Re: setting size of 2-D array at constructor issue

 
0
  #3
Nov 24th, 2008
o ok that makes sense. thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC