C++ Debug

Debug FAQ

error: if condition proceeds with a bool variable that is false

fake_indices_ = false; // member variable initialized somewhere else

bool MultiviewGICP::initCompute() {
  std::cout << "fake_indices_ = " << fake_indices_ << std::endl;
  // this prints 0, and confirms that fake_indices_ was indeed initialized as false
  if (fake_indices_) {
    std::cout << "we are getting here." << std::endl;
    // the weird thing is that this line of code gets printed out,
    // meaning that we reached this code block, suppressing the if condition
  // the root cause of this problem was the missing of the return statement below,
  // which is required of this function.
  // Without it, program proceeds with whatever code being compiled in the memory.
  return true;
  // if you put directly "if (false)", the above code block will not be executed,
  // since they may be optimized out during compilation.

error: variable or field declared void

// for example it happens in this case
void initializeJSP(unknownType Experiment);

// another example (due to the missing 'typename' keyword)
template <typename PointT>
void func(pcl::PointCloud<PointT>::Ptr& cloud) {} // error
void func(typename pcl::PointCloud<PointT>::Ptr& cloud) {} // correct

reference: https://stackoverflow.com/questions/364209/variable-or-field-declared-void

Last updated