You need to do it in an initializer list:
Bar(Foo* _foo) : foo(_foo) {
}
(Note that I renamed the incoming variable to avoid confusion.)
More Related Contents:
- What is this weird colon-member (” : “) syntax in the constructor?
- What does a colon following a C++ constructor name do? [duplicate]
- Do I really need to implement user-provided constructor for const objects?
- Why does C++ not have a const constructor?
- Why must const members be initialized in the constructor initializer rather than in its body?
- How do I initialize a const data member?
- What is the difference between const int*, const int * const, and int const *?
- Default constructor with empty brackets
- What are the rules for calling the base class constructor?
- static const vs #define
- const vs constexpr on variables
- Does const mean thread-safe in C++11?
- How to initialize const member variable in a class?
- Throwing exceptions from constructors
- A most vexing parse error: constructor with no arguments
- C++0x lambda capture by value always const?
- Is passing a C++ object into its own constructor legal?
- C++: Where to initialize variables in constructor [duplicate]
- Is there any difference between “T” and “const T” in template parameter?
- Is a `=default` move constructor equivalent to a member-wise move constructor?
- What is the difference between a macro and a const in C++?
- Forwarding all constructors in C++0x
- What is the difference between a const reference and normal parameter?
- Different ways of initializing an object in c++
- Const correctness in C vs C++
- Class inherited from class without default constructor
- const in C vs const in C++
- non-const pointer argument to a const double pointer parameter
- Why must a std::ranges::filter_view object be non-const for querying its elements?
- C++ “error: passing ‘const std::map’ as ‘this’ argument of …”