Thank you for answers. I am new to C++ and want to learn its basic rules at the beginning. Actually I want to write a matrix class and use it for scientific computing. They say vector class is not fast especially for small matrices. There may be a class from blitz which is fast. I can use it, but later.
Because I didnt know how to allocate memory from inside the constructor. Thank you for pointing out initializer l...
User Profile
Collapse
-
If I use the A in the member function in which the memory is allocated there is no problem. Every thing is OK. However I want to use it outside the member function also. For this purpose, When I make an declaration as
double* A[n]
compiler says:
invalid use of non-static data member `MyClass::n'
If I make n is static, there will be only one n while there are several MyClass objects. Each of them...Leave a comment:
-
The code is below:
...Code:#include <iostream> using namespace std; class MyClass { public: int n; double* A; // One of the problem is the declaration I think ... MyClass(int); virtual ~MyClass(); void Print(); }; MyClass::MyClass(int _n) { n=_n; double* A=new double[n];Leave a comment:
-
runn started a topic Can a class has a member array which will be dynamically allocated during runtime?in CCan a class has a member array which will be dynamically allocated during runtime?
Can a class has a member array which will be dynamically allocated during runtime? Such as
double* A=new double[n]
here n is an integer member variable and will be determined during runtime and the class will have the array *A allocated.
Thanks in advance.
No activity results to display
Show More
Leave a comment: