I’ve got a program with a treeview class, a console class, and an options class.
I’d like to pass the treeview object to the options object, and be able to access dynamic values inside of the treeview (file lists and so on).
I’ve tried passing by reference, and it compiles, but through a few debug messages, I can tell it’s not the same object, so the values are all empty.
Options panel Init header:
public:
void Init (HWND, PnlConsole&, PnlTree&);
...
private:
PnlTree tree_;
PnlConsole console_;
...
Options panel Init function:
void PnlOptions::Init(HWND hwnd0, PnlConsole& console0, PnlTree& tree0) {
tree_ = tree0;
console_ = console0;
...
Instantiation of classes in main file:
PnlTree pnl_tree;
PnlOptions pnl_options;
PnlConsole pnl_console;
Call to Init inside main function:
pnl_options.Init(hwnd0, pnl_console, pnl_tree);
I’ve been working at this for a long time (as some people have read on my previous questions) and it’s very frustrating. Can someone help me to get this working?
console0andtree0are being passed by reference intoInit()but the assigments within the function result in copies of the arguments, due to the types oftree_andconsole_.It is not possible to change the types of
tree_andconsole_in this context becauseInit()is not the constructor and reference types must be assigned immediately (in the constructor initializer list).A solution would be to make the types pointers and take the addresses of the arguments. Note that there is a lifetime requirement in that the objects referred to by
console0andtree0must exist for as long as thePnlOptionsrequires them.