in my object State, i’d like to have object pq. but pq needs to be initialized with a parameter. is there a way to include a class that depends on a parameter into another class?
file.h
class Pq { int a; Pq(ClassB b); }; class State { ClassB b2; Pq pq(b2); State(ClassB b3); };
file.cc
State::State(ClassB b3) : b2(b3) {}
You can initialize it in the initializer list, just like you do with
b2:Keep in mind that members are initialized in the order they are declared in the header file, not the order of the initializers in the initializer list.
You need to remove the attempt at initialize it in the header as well: