2

GTKmm ウィンドウ プログラムを作成しています。メイン ウィンドウには、英語用と中国語用の 2 つのボタンが作成されます。ユーザーはボタンをクリックして、適切な言語で別のウィンドウを表示できます。現在、メイン ウィンドウ内の複数アイテム コンテナーの初期化に問題があります。これは、Gtk::HBox を継承する MainWindowPane 型のオブジェクトです。

作成しようとすると、コンパイラは次のエラーを発行します。

$ make 
g++ -g `pkg-config gtkmm-2.4 --cflags` -c MainWindow.cpp  
g++  -g -o QPI_frontend main.o MainWindow.o StartButton.o `pkg-config gtkmm-2.4 --libs`  
MainWindow.o: In function `MainWindow':  
/home/dmurvihill/Documents/QPI_frontend/MainWindow.cpp:9: undefined reference to   `MainWindowPane::MainWindowPane()'  
/home/dmurvihill/Documents/QPI_frontend/MainWindow.cpp:9: undefined reference to  `MainWindowPane::MainWindowPane()'  
collect2: ld returned 1 exit status  
make: *** [QPI_frontend] Error 1  

適切なライブラリを含めるために、最新バージョンの gcc と pkg-config を使用しています。私もジャバ派です。

/*
 * MAIN_WINDOW.H
 * Responsible for creating "slave" RSED windows. Can create English or Chinese
 * versions of the demo, and can destroy them all with one click.
 */  
#ifndef MAINWINDOW_H  
#define MAINWINDOW_H  

#include <gtkmm/window.h>

//#include "SlaveWindow.h"
#include "StartButton.h"
#include "MainWindowPane.h"

class MainWindow : public Gtk::Window
{
public:
    MainWindow();   
private:
    MainWindowPane pane;
//  std::list<SlaveWindowThread> windows;       // Keeps track of all windows that have been created thus far.
    void destroyAllWindows();           // Iterates through the linked list and destroys each window.
};
#endif      //ifndef MAINWINDOW_H

/* 
 * MAIN_WINDOW.CPP
 *
 */  
#include "MainWindow.h"  
#include "MainWindowPane.h"  
#include "StartButton.h"  

MainWindow::MainWindow()// : /*list,*/ pane(/*list*/)
{
    pane;
}

void MainWindow::destroyAllWindows()
{
    //gtk_widget_destroy(*this);
    // TODO: Destroy all the other windows too.
}

/*
 * MAIN_WINDOW_PANE.H
 */  
#ifndef MAINWINDOWPANE_H  
#define MAINWINDOWPANE_H  

#include <gtkmm/box.h>
#include <gtkmm/button.h>

//#include "SlaveWindow.h"
#include "StartButton.h"

class MainWindowPane : public Gtk::HBox
{
public:
    MainWindowPane(/*&(std::list)*/);   
private:
    StartButton englishButton;      // Used to create a new RSED demo screen.
    StartButton chineseButton;      // Used to create a new RSED demo in chinese.
//  std::list<SlaveWindow> windows;     // Keeps track of all windows that have been created thus far.
    void destroyAllWindows();       // Iterates through the linked list and destroys each window.
};
#endif      //ifndef MAINWINDOWPANE_H

/* 
 * MAIN_WINDOW.CPP
 *
 */  
#include "MainWindowPane.h"  
#include "StartButton.h"  

MainWindowPane::MainWindowPane(/*&(std::list)*/) : 
    englishButton(StartButton::ENGLISH/*,&(std::list)*/), 
    chineseButton(StartButton::CHINESE/*,&(std::list)*/)
{
    pack_start(englishButton);
    englishButton.show();
    pack_start(chineseButton);
    chineseButton.show();
}

void MainWindow::destroyAllWindows()
{
    //gtk_widget_destroy(*this);
    // TODO: Destroy all the other windows too.
}
4

2 に答える 2

8

未定義の参照エラーは、欠落している関数の定義を (ファイルに実装を書き込むことによって.cpp) 書き忘れたか、適切なオブジェクト ファイルまたはライブラリを最終的なバイナリにリンクするのを忘れたことを意味します。

この場合、それは後の理由です。MainWindowPane.omakefile のリンカー コマンドに次のように含める必要があります。

g++  -g -o QPI_frontend main.o MainWindow.o StartButton.o `pkg-config gtkmm-2.4 --libs`
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        you need MainWindowPane.o in here
于 2010-08-17T21:06:36.180 に答える
0

存在しない MainWindowPane のデフォルト コンストラクターを呼び出そうとしていると不平を言っています。

私の推測では、MainWindowPane はパラメーター付きの ctor のみを定義し、それを基本クラスとして使用しており派生クラスの ctor を定義していないか、定義した ctor がパラメーター付きの基本を呼び出していません。

class MyDerived : public MainWindowPane
{
  public:
      MyDerived() {....}    // bad

      MyDerived(int x) : MainWindowPane(x)  // good
          {....} 

アップデート:

OK、上記(コードを投稿する前に書かれたもの)を無視してください。このセリフに文句を言っているようだ」

MainWindow::MainWindow()// : /*list,*/ pane(/*list*/) 
{ 
    pane;     // Error HERE.
}

そして、その行の目的が何であるかは本当にわかりません。何もせずに、データ メンバーを参照しているだけです。おそらく削除される可能性があります。

UPDATE2: pane何もしない場合、デフォルトで構築されます:

MainWindow::MainWindow()
{ 
}
于 2010-08-17T20:52:31.350 に答える