2016-11-25 86 views
3

好吧,我正在學習C++中的base/super classes/inheritance /和虛函數。因此,下面是一個在頭文件中設置的Get/Set函數,我正在研究Mutator SetSize(int,int);找到一個基類/超級類的成員的實現

class VTKCOMMONCORE_EXPORT vtkWindow : public vtkObject 
{ 
public: 
    vtkTypeMacro(vtkWindow,vtkObject); 
    void PrintSelf(ostream& os, vtkIndent indent); 
. 
. 
. 

     // Description: 
     // Set/Get the size of the window in screen coordinates in pixels. 
     virtual int *GetSize(); 
     virtual void SetSize(int,int); 
     virtual void SetSize(int a[2]); 

據我瞭解關於繼承和虛函數的是,這僅僅是建立功能,將需要在別處定義是否在這個頭或其他一些。我正在努力尋找SetSize是在哪裏定義的,我在它的main中提供了它的值,但是Size在哪裏被設置爲一個變量,然後該變量在哪裏進入定義實際窗口大小的較大進程。很明顯,我不會告訴你所有的信息來告訴我它到底在哪裏,但我不知道如何從我的主函數中調用它到在渲染器中設置實際的窗口大小。

我希望所有這些都有道理,並且我使用的是正確的術語,我將不勝感激任何幫助或進一步閱讀建議,因爲我不知道還有什麼可以搜索以找到此答案。

下面是引用

/*========================================================================= 

    Program: Visualization Toolkit 
    Module: vtkWindow.h 

    Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 
    All rights reserved. 
    See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 

    This software is distributed WITHOUT ANY WARRANTY; without even 
    the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
    PURPOSE. See the above copyright notice for more information. 

=========================================================================*/ 
// .NAME vtkWindow - window superclass for vtkRenderWindow 
// .SECTION Description 
// vtkWindow is an abstract object to specify the behavior of a 
// rendering window. It contains vtkViewports. 

// .SECTION see also 
// vtkRenderWindow vtkViewport 

#ifndef vtkWindow_h 
#define vtkWindow_h 

#include "vtkCommonCoreModule.h" // For export macro 
#include "vtkObject.h" 

class vtkUnsignedCharArray; 

class VTKCOMMONCORE_EXPORT vtkWindow : public vtkObject 
{ 
public: 
    vtkTypeMacro(vtkWindow,vtkObject); 
    void PrintSelf(ostream& os, vtkIndent indent); 

    // Description: 
    // These are window system independent methods that are used 
    // to help interface vtkWindow to native windowing systems. 
    virtual void SetDisplayId(void *) = 0; 
    virtual void SetWindowId(void *) = 0; 
    virtual void SetParentId(void *) = 0; 
    virtual void *GetGenericDisplayId() = 0; 
    virtual void *GetGenericWindowId() = 0; 
    virtual void *GetGenericParentId() = 0; 
    virtual void *GetGenericContext() = 0; 
    virtual void *GetGenericDrawable() = 0; 
    virtual void SetWindowInfo(char *) = 0; 
    virtual void SetParentInfo(char *) = 0; 

    // Description: 
    // Set/Get the position in screen coordinates of the rendering window. 
    virtual int *GetPosition(); 
    virtual void SetPosition(int,int); 
    virtual void SetPosition(int a[2]); 

    // Description: 
    // Set/Get the size of the window in screen coordinates in pixels. 
    virtual int *GetSize(); 
    virtual void SetSize(int,int); 
    virtual void SetSize(int a[2]); 

    // Description: 
    // GetSize() returns the size * this->TileScale, whereas this method returns 
    // the size without multiplying with the tile scale. 
    int *GetActualSize(); 

    // Description: 
    // Get the current size of the screen in pixels. 
    virtual int  *GetScreenSize() = 0; 

    // Description: 
    // Keep track of whether the rendering window has been mapped to screen. 
    vtkSetMacro(Mapped,int); 
    vtkGetMacro(Mapped,int); 
    vtkBooleanMacro(Mapped,int); 

    // Description: 
    // Turn on/off erasing the screen between images. This allows multiple 
    // exposure sequences if turned on. You will need to turn double 
    // buffering off or make use of the SwapBuffers methods to prevent 
    // you from swapping buffers between exposures. 
    vtkSetMacro(Erase,int); 
    vtkGetMacro(Erase,int); 
    vtkBooleanMacro(Erase,int); 

    // Description: 
    // Keep track of whether double buffering is on or off 
    vtkSetMacro(DoubleBuffer,int); 
    vtkGetMacro(DoubleBuffer,int); 
    vtkBooleanMacro(DoubleBuffer,int); 

    // Description: 
    // Get name of rendering window 
    vtkGetStringMacro(WindowName); 
    vtkSetStringMacro(WindowName); 

    // Description: 
    // Ask each viewport owned by this Window to render its image and 
    // synchronize this process. 
    virtual void Render() = 0; 

    // Description: 
    // Get the pixel data of an image, transmitted as RGBRGBRGB. The 
    // front argument indicates if the front buffer should be used or the back 
    // buffer. It is the caller's responsibility to delete the resulting 
    // array. It is very important to realize that the memory in this array 
    // is organized from the bottom of the window to the top. The origin 
    // of the screen is in the lower left corner. The y axis increases as 
    // you go up the screen. So the storage of pixels is from left to right 
    // and from bottom to top. 
    // (x,y) is any corner of the rectangle. (x2,y2) is its opposite corner on 
    // the diagonal. 
    virtual unsigned char *GetPixelData(int x, int y, int x2, int y2, 
             int front) = 0; 
    virtual int GetPixelData(int x, int y, int x2, int y2, int front, 
          vtkUnsignedCharArray *data) = 0; 

    // Description: 
    // Return a best estimate to the dots per inch of the display 
    // device being rendered (or printed). 
    vtkGetMacro(DPI,int); 
    vtkSetClampMacro(DPI,int,1,VTK_INT_MAX); 

    // Description: 
    // Attempt to detect and set the DPI of the display device by querying the 
    // system. Note that this is not supported on all backends, and this method 
    // will return false if the DPI could not be detected. Use GetDPI() to 
    // inspect the detected value. 
    virtual bool DetectDPI() { return false; } 

    // Description: 
    // Create a window in memory instead of on the screen. This may not be 
    // supported for every type of window and on some windows you may need to 
    // invoke this prior to the first render. 
    vtkSetMacro(OffScreenRendering,int); 
    vtkGetMacro(OffScreenRendering,int); 
    vtkBooleanMacro(OffScreenRendering,int); 

    // Description: 
    // Make the window current. May be overridden in subclasses to do 
    // for example a glXMakeCurrent or a wglMakeCurrent. 
    virtual void MakeCurrent() {} 

    // Description: 
    // These methods are used by vtkWindowToImageFilter to tell a VTK window 
    // to simulate a larger window by tiling. For 3D geometry these methods 
    // have no impact. It is just in handling annotation that this information 
    // must be available to the mappers and the coordinate calculations. 
    vtkSetVector2Macro(TileScale,int); 
    vtkGetVector2Macro(TileScale,int); 
    void SetTileScale(int s) {this->SetTileScale(s,s);} 
    vtkSetVector4Macro(TileViewport,double); 
    vtkGetVector4Macro(TileViewport,double); 

protected: 
    int OffScreenRendering; 
    vtkWindow(); 
    ~vtkWindow(); 

    char *WindowName; 
    int Size[2]; 
    int Position[2]; 
    int Mapped; 
    int Erase; 
    int DoubleBuffer; 
    int DPI; 

    double TileViewport[4]; 
    int TileSize[2]; 
    int TileScale[2]; 

private: 
    vtkWindow(const vtkWindow&); // Not implemented. 
    void operator=(const vtkWindow&); // Not implemented. 
}; 

#endif 
+0

不,它沒有任何意義。 setSize()將在定義getSize()的任何地方被定義。通常,在實現此類的所有成員的同一翻譯單元中。 –

+0

沒有在這裏定義,似乎是他們做事情的方式許多函數設置,但沒有定義,我試過使用resharper VS2015,仍然無法追查它被定義實施的地方。 –

回答

0

確定整個頭文件我找到了答案,我的問題

在VTK header.h有相應的文件header.cxx所有headerfiles。函數定義發生在header.cxx文件中。

+0

歡迎來到C++!您已經在C/C++中確定了一個重要且常見的模式 - 在一個文件中提供定義,在另一個文件中提供實現。我要發表評論指出[優秀的網站教程](http://www.cplusplus.com/forum/articles/10627/),涉及此主題和其他內容。還值得一提的是,您可能會看到頭文件的'.hpp'和'.hxx'文件擴展名,以及源文件的'.cpp'。有時,人們試圖將'.h'和'.c'用於*純C代碼*,以及'.hpp' /'.hxx'和'.cpp' /'.cxx'用於C++代碼。不是一個標準,但如果你的項目是混合的很好做。快樂的C++! – sjm324

+0

非常感謝。 –

相關問題