| | |
setting size of 2-D array at constructor issue
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 60
Reputation:
Solved Threads: 1
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?
Line 13 is the constructor declaration.
Here is my code
Thanks in advance
C++ Syntax (Toggle Plain Text)
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
Here is my code
CPP Syntax (Toggle Plain Text)
#include<string> #include<fstream> using namespace std; class AdjacencyMatrix { private: bool* matrix; public: AdjacencyMatrix(int const numberOfNodes, string fileName) { matrix = new bool[numberOfNodes[numberOfNodes]; //two dimensional array populateArray(fileName); } void populateArray(string filName); };
Thanks in advance
I find that it compiles fine, after you take the excess
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.
(using VC++ 2005)
[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.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Key input
- Next Thread: Key imput without getch()
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






