Hello everyone, Is this valid? template struct ClassA { typedef A value_type; value_type* data_; explicit ClassA(size_t n) : data(new value_type[]()) {} // note the () after [] // other stuff }; Here A is any type, including primitive types. I run valgrind on this code and it gives me the "Conditional jump or move depends on uninitialised value(s)" error. ...
Hi, I'm wondering if there is a way to initialized a member array just as the initialization of a member variable? Or I have to initialized the array inside the function body of the constructor? Thanks, Peng #include struct A { A() : array({0, 1, 2, 3}), variable(100) { } int array[4]; int variable; }; int main() { A a; ...
Hi, If i have the following struct: struct t { const int x;// = 0; char name [ x ]; }; its gives an error saying that x is undefined. So I want to initialize x and use it to initalize other members. How do I do this? Or should I use some other way? Thanks, ...ab
Hi, Consider the following (*). Is there a way to rewrite it so that it remains convenient (N is being recomputed when array v is modified) *and* compiles :) Thanks, -Mathieu (*) template struct Functor { T values[N]; }; int main() { const double v[] = {0, 1, 4, 9, 16, 25, 36 }; const unsigned ...
* heng: If the data member of a class is an array, how to initialize? > I tried the following, but it is wrong. > class A { public: int a[3]; A():a({0,0,0}){} }; If you just want to default-initialize (all zeroes for the above), A(): a() {} However, old versions of Visual C++ don't support that. A better way is to ...
Peter Olcott wrote:[color=blue] > Is this possible in C++ ???[/color] Please, don't write parts of your question in your subject. Make sure everything is in your post. Of course it is possible to initialize static array members, it is even mandatory. class C { public: static int a[10]; }; int C::a[10] = {1, 2, 3}; Jonathan
I have some test code which demonstrates the problem. I know I could solve this by just returning a pointer, but I better use a reference. In real code, what I actually want to return is a reference to an array of function pointers. But the code below is good enough to show the problem. Thanks. #define MAX_DEC 11 static char ...