我有一個頭文件'Custom.h'有兩個類,ResizeLabel和ResizePanel,用於構建一個包含自定義控件的dll。如果我使用內ResizeLabel定製:: ResizePanel它失敗:使用Name :: Class1從Name :: Class2在同一個Name.h文件中失敗
error C2039: 'ResizePanel' : is not a member of 'Custom'
還有在Errorlist警告:
Exception of type 'System.Exception' was thrown
我想象的警告是相關的。難道是因爲Visual Studio試圖從包含它的代碼中加載包含Custom :: ResizePanel的dll文件嗎?
的代碼如下:
namespace Custom {
public ref class ResizeLabel : public System::Windows::Forms::Label
{
protected: virtual void OnTextChanged(System::EventArgs^ e) override {
__super::OnTextChanged(e);
// Not elegant I know,
// but this is just to force the panel to process the size change
dynamic_cast<Custom::ResizePanel^>(this->Parent)->CurrentWidth = 0;
}
...
};
public ref class ResizePanel : public System::Windows::Forms::Panel
{ ... };
}
我做了它的dynamic_cast只是爲了減少報告的錯誤的數量。
我該如何最好地避免此問題?
你原則上是正確的,但編譯器反對在類之外的覆蓋 – bobinski 2011-02-27 08:12:19
糟糕,按下輸入太快 - 我期待這個多線盒去下一行!我習慣於比這更好的編譯器,它應該解析文件兩次!最後一個函數應該讀取'void ResizeLabel :: OnTextChanged(System :: EventArgs^e) {_0super :: OnTextChanged(e); // Not elegant我知道, //但這只是強制面板處理尺寸變化 dynamic_cast(this-> Parent) - > CurrentWidth = 0; }' –
bobinski
2011-02-27 08:15:46
Thanks @bobinski,fixed – 2011-02-27 17:02:39