這是我的課:爲什麼在靜態轉換之後調用構造函數?
class AComponent : public nts::IComponent
{
public:
AComponent(const size_t &maxInputs, const size_t &maxOutputs, const size_t &value);
AComponent(nts::AComponent &);
virtual ~AComponent();
virtual nts::Tristate Compute(size_t pin_num_this = 1);
virtual void SetLink(size_t pin_num_this,
nts::IComponent &component,
size_t pin_num_target);
void setComponent(const size_t &components, nts::Tristate &state);
virtual void Dump(void) const;
nts::Tristate &getComponent(const size_t &pin);
protected:
std::vector <nts::Tristate *> _components;
size_t _maxInputs;
size_t _maxOutputs;
};
,當我嘗試調用該行:
this->_components[pin_num_this] =
&static_cast<nts::AComponent>(component).getComponent(pin_num_target);
我有這種情況發生此編譯錯誤:
sources/AComponant.cpp:33:76: error: no matching function for call to ‘nts::AComponent::AComponent(nts::IComponent&)’
this->_components[pin_num_this] = &static_cast<nts::AComponent>(component).getComponent(pin_num_target);
如果我執行構造函數,它在這裏。問題是,我不想操縱IComponent
,我想操縱AComponent
。你知道爲什麼會發生這種情況嗎?
編輯:
this->_components
是向量。它在構造函數中聲明是這樣的:
this->_components.reserve(maxInputs + maxOutputs + 2);
是什麼'component'的類型? –
請告訴我們'component'是如何聲明的。 –