我想在類的結構和訪問函數成員中定義類的對象。是否有可能實現這一目標?結構中的類
使用下面的代碼,我得到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中的不同。)這是你的問題嗎? –
「我有一個獨特的」!? –