Z
zl2k
hi,
I got a strange problem when running my problem. Basically, if I do
int temp = someXYZ->someArray.size();
std::cout<<temp<<std::endl; //this temp is all right, say, temp is 12
std::cout<<-(someABC->someXYZ->someArray.size())<<std::endl; // it
will print a large unreasonable number
People suggests that this is due to the uninitialized variable when an
instance of a class is created. I checked many times but can't find
the error. I post the constructor as following, please let me know if
I am doing all right.
variables in head file abc.h:
std::vector<unsigned short> counter;
std::vector<gsl_vector*> image;
std::vector<boost::shared_ptr<xyz> > layers;
constructor in cpp file abc.cpp:
abc::abc(): counter(100, 0), image(0), layers(0) {
//construct counter, image here
for (int i = 0; i < 10; i++){
boost::shared_ptr<xyz> ptr;
layers.push_back(ptr);
}
}
//main is in abc.cpp
variables in the header file xyz.h:
std::vector<std::vector<unsigned long> > Lout;
std::vector<unsigned short> LoutPos;
constructor in cpp file xyz.cpp:
xyz::xyz(): Lout(0), LoutPos(0) {}
// The rows of the two dimensional std array Lout is dynamically
insert or delete while running the program.
Duplicatted type of variables are dropped to make it simple.
How can I detect if a variable is correctly initialized while running
the problem? Thanks for comments.
zl2k
I got a strange problem when running my problem. Basically, if I do
int temp = someXYZ->someArray.size();
std::cout<<temp<<std::endl; //this temp is all right, say, temp is 12
std::cout<<-(someABC->someXYZ->someArray.size())<<std::endl; // it
will print a large unreasonable number
People suggests that this is due to the uninitialized variable when an
instance of a class is created. I checked many times but can't find
the error. I post the constructor as following, please let me know if
I am doing all right.
variables in head file abc.h:
std::vector<unsigned short> counter;
std::vector<gsl_vector*> image;
std::vector<boost::shared_ptr<xyz> > layers;
constructor in cpp file abc.cpp:
abc::abc(): counter(100, 0), image(0), layers(0) {
//construct counter, image here
for (int i = 0; i < 10; i++){
boost::shared_ptr<xyz> ptr;
layers.push_back(ptr);
}
}
//main is in abc.cpp
variables in the header file xyz.h:
std::vector<std::vector<unsigned long> > Lout;
std::vector<unsigned short> LoutPos;
constructor in cpp file xyz.cpp:
xyz::xyz(): Lout(0), LoutPos(0) {}
// The rows of the two dimensional std array Lout is dynamically
insert or delete while running the program.
Duplicatted type of variables are dropped to make it simple.
How can I detect if a variable is correctly initialized while running
the problem? Thanks for comments.
zl2k