# C++ Debug

## Debug FAQ

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

```cpp
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

```cpp
// 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.hanzheteng.com/development/c++/c++-debug.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
