RSS Forums RSS

setting size of 2-D array at constructor issue

Please support our C++ advertiser: Programming Forums
Reply
Posts: 42
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 0
chunalt787 chunalt787 is offline Offline
Light Poster

setting size of 2-D array at constructor issue

  #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?

In file included from Main.cpp:1:
AdjacencyMatrix.h: In constructor ‘AdjacencyMatrix::AdjacencyMatrix(int, std::string)’:
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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,495
Reputation: vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all vmanes is a name known to all 
Solved Threads: 167
vmanes's Avatar
vmanes vmanes is offline Offline
Nearly a Posting Virtuoso

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

  #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)
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote  
Posts: 42
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 0
chunalt787 chunalt787 is offline Offline
Light Poster

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

  #3  
Nov 24th, 2008
o ok that makes sense. thanks
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 428 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:15 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC