我有一个头文件'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