How can I assign an instance variable without calling its constructor in C++? -
basically, have class called visamux , class called muxpath. muxpath has visamux private instance variable. want muxpath's constructor assign instance variable given visamux object without invoking empty visamux() constructor.
5 muxpath::muxpath(const uint& clk_sel, const uint& lane_sel, const visamux& mux){ 6 clk_sel = clk_sel; 7 lane_sel = lane_sel; 8 mux = mux; 9 }
this code results in error:
muxpath.cpp:5: error: no matching function call ‘visamux::visamux()’ visamux.h:20: candidates are: visamux::visamux(const std::string&, const uint&, const uint&, const std::vector<visalane, std::allocator<visalane> >&, const std::vector<visaresource, std::allocator<visaresource> >&)
as can see, errors on first line (line 5), seems somehow const visamux& mux invoking visamux(), doesn't exist. happens if visamux mux.
i don't want call empty constructor visamux because want visamux created passing constructor necessary parameters.
how can this?
use constructor initialization list:
muxpath::muxpath(const uint& clk_sel, const uint& lane_sel, const visamux& mux) : clk_sel(clk_sel) , lane_sel(lane_sel) , mux(mux) {}
Comments
Post a Comment