【发布时间】:2013-09-21 09:52:58
【问题描述】:
我想在一个结构中定义一个类的对象并访问该类的函数成员。有没有可能做到这一点?
使用以下代码,我在ps_test->AttachToInput(2145); 遇到了分段错误。我不知道原因,一切对我来说都是正确的:
class test
{
public:
test();
virtual ~test();
int init_app(int argc, char* argv[]);
virtual void AttachToInput(int TypeNumber, int DeviceNo=0);
}
struct capture
{
test h_app;
gint port;
};
main()
{
struct capture h_cap;
test *ps_test = &h_cap.h_app;
ps_test->AttachToInput(2145);
}
【问题讨论】:
-
你遇到了什么问题?
-
你不能调用
AttachToInput,因为它是受保护的,所以只有派生类可以使用它。 (它的工作方式与 Java 不同。)这是您的问题吗?
标签: c++ class structure subclassing