C/C++ - 嵌套类继承封闭类
我想使用嵌套类作为我正在构建的应用程序的一部分。我的第一段代码(头文件,我在其中包含了这个问题的一些代码)如下:
class Window {
public:
indev::Thunk32<Window, void ( int, int, int, int, void* )> simpleCallbackThunk;
Window() {
simpleCallbackThunk.initializeThunk(this, &Window::mouseHandler); // May throw std::exception
}
~Window();
class WindowWithCropMaxSquare;
class WindowWithCropSelection;
class WindowWithoutCrop;
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("Father");
}
private:
void assignMouseHandler( CvMouseCallback mouseHandler );
};
class Window::WindowWithCropMaxSquare : public Window {
public:
WindowWithCropMaxSquare( char* name );
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("WWCMS");
}
};
class Window::WindowWithCropSelection : public Window {
public:
WindowWithCropSelection( char* name );
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("WWCS");
}
};
class Window::WindowWithoutCrop : public Window {
public:
WindowWithoutCrop( char* name );
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("WWOC");
}
};
现在,我想在 MAIN 中实例化一个 WindowWithCropMaxSquare 类并执行 mouseHandler< /代码> 功能。
在 MAIN 中我有
Window::WindowWithCropMaxSquare *win = new Window::WindowWithCropMaxSquare("oopa");
win->mouseHandler(1,1,1,1,0);
但是,这会在链接阶段导致问题。我收到以下错误:
错误 1 错误 LNK2019:函数 _main c:\Users\ 中引用的无法解析的外部符号“public: __thiscall Window::WindowWithCropMaxSquare::WindowWithCropMaxSquare(char *)”(??0WindowWithCropMaxSquare@Window@@QAE@PAD@Z)尼古拉斯\文档\视觉工作室2010\项目\AFRTProject\AFRTProject\AFRTProject.obj
那么,有人可以让我知道如何解决这个问题吗?
I would like to use nested classes as a part of an application I am building. The first piece of code I have (header file, which I included some code for this question) is the following:
class Window {
public:
indev::Thunk32<Window, void ( int, int, int, int, void* )> simpleCallbackThunk;
Window() {
simpleCallbackThunk.initializeThunk(this, &Window::mouseHandler); // May throw std::exception
}
~Window();
class WindowWithCropMaxSquare;
class WindowWithCropSelection;
class WindowWithoutCrop;
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("Father");
}
private:
void assignMouseHandler( CvMouseCallback mouseHandler );
};
class Window::WindowWithCropMaxSquare : public Window {
public:
WindowWithCropMaxSquare( char* name );
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("WWCMS");
}
};
class Window::WindowWithCropSelection : public Window {
public:
WindowWithCropSelection( char* name );
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("WWCS");
}
};
class Window::WindowWithoutCrop : public Window {
public:
WindowWithoutCrop( char* name );
virtual void mouseHandler( int event, int x, int y, int flags, void *param ) {
printf("WWOC");
}
};
Now, I want to instantiate a WindowWithCropMaxSquare
class in MAIN and execute the mouseHandler
function.
In MAIN I have
Window::WindowWithCropMaxSquare *win = new Window::WindowWithCropMaxSquare("oopa");
win->mouseHandler(1,1,1,1,0);
However, this causes a problem at the linking stage. I got the following error:
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Window::WindowWithCropMaxSquare::WindowWithCropMaxSquare(char *)" (??0WindowWithCropMaxSquare@Window@@QAE@PAD@Z) referenced in function _main c:\Users\Nicolas\documents\visual studio 2010\Projects\AFRTProject\AFRTProject\AFRTProject.obj
So, can anyone please let me know how to address this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要两件事:每个构造函数的主体,以及正确的常量性。
只是一个没有任何定义(主体)的声明。正如您在评论中所暗示的那样,空的构造函数主体
也是我非常怀疑
需要一个采用 const char* 的构造函数,因为您给它一个常量(右值):
或者
编译器将不要将常量作为参数提供给采用非常量的函数,因为此类函数向您表明它可以修改给定的参数,显然不允许使用常量。
You need two things: a body for each constructor, and correct const'ness.
is just a declaration without any definition (body). Empty constructor body, as you imply in your comment, would be
Also I very much suspect that
requires a constructor that takes
const char*
since you are giving it a constant (an rvalue):or
The compiler will not give a constant as argument to a function that takes non-const since such function is indicating to you that it may modify the given argument, clearly not allowed for a constant.