2013-01-20 44 views
1

自從昨晚我一直堅持使用它,對於我的生活,我一直無法弄清楚爲什麼會發生這種情況。我必須錯過一些非常簡單的事情。C++ - 錯誤C4430:缺少類型說明符(對於構造函數???)

我正在製作一個OpenGL程序。在這個程序中,我正在製作一個DialogBox類。下面是代碼:

//--------------------------------------------------------------- 
//DialogBox.h 
//--------------------------------------------------------------- 

#include <vector> 

class DialogBox 
{ 
    private: 

     float X; float Y; float Z; 
     float Width; 
     float Height; 

     float RED; 
     float GREEN; 
     float BLUE; 
     float ALPHA; 

     int currentLine; 
     int maxLines; //How many lines of text this dialog box can hold 
     int maxChars; //How many chars each line of text can hold 

     std::vector< std::vector<char> >Text; //Text contents of the Dialog Box 

     unsigned int vertexArray_DialogBox; 
     unsigned int vertexBuffer_DialogBox; 


    public: 

     DialogBox(); 
     DialogBox(float width, float height); 

     void draw(); 
     void draw(float x, float y, float z); 

}; 

//------------------------------------------------------------------------ 
//DialogBox.cpp 
//------------------------------------------------------------------------ 

#include <iostream> 
#include "DialogBox.h" 

DialogBox::DialogBox() 
{ 
    X = 0.0f; Y = 0.0f; Z = 0.0f; 

    Width = 1.0f; 
    Height = 1.0f; 

    RED = 0.0f; 
    GREEN = 1.0f; 
    BLUE = 1.0f; 
    ALPHA = 1.0f; 

    //For HELVETICA_18 ---------------------- 
    static const float letter_width = 0.03f; 
    static const float letter_height = 0.04f; 
    static const float line_height = 0.1f; 
    //--------------------------------------- 


    maxLines = Height/line_height - 4; 
    maxChars = Width/letter_width - 2; 

    Text.resize(maxLines); 
    for(int i = 0; i < maxLines; i++) 
    { 
     Text[i].resize(maxChars); 
    } 
} 

DialogBox::DialogBox(float width, float height) 
{ 
    Width = width; 
    Height = height; 
    //The rest of the initialization codes 
} 

void DialogBox::draw() 
{ 
    //OpenGL Drawing codes 
} 

void DialogBox::draw(float x, float y, float z) 
{ 
    X = x; Y = y; Z = z; 
    draw(); 
} 

,編譯器拋出此錯誤消息:

enter image description here

我一直在拉我的頭髮,但我無法弄清楚什麼是編譯器參考。它必須是非常簡單的東西(比如代碼中的錯字或類似的東西)。預先感謝您的幫助。

+0

嘗試將您的類重命名爲比DialogBox更不可能的名稱。微軟已經提供了這個名字。作爲替代方案,請參閱是否包含或任何系統標題幫助。 –

+0

賓果!你能否將此作爲答覆發佈,以便我可以接受它?非常感謝你! – TATN

回答

3

當我編譯你的代碼時,我在DialogBox::draw()上得到一個錯誤,因爲你沒有在那裏指定返回類型。具體來說,這是在實施,而不是聲明。這是我在代碼中發現的唯一編譯器錯誤。也許你的編譯器只是標記錯誤的行?

+0

哦,我在複製我的代碼時錯過了draw()函數之前的「void」。對於那個很抱歉。我在第一篇文章中編輯和更新了我的代碼。 – TATN

7

同一行上的警告是什麼?

宏 'DialogBoxA'

DialogBox一個#define -d宏沒有足夠的實際參數?如果是這樣,那可能會搞砸了。

+0

這看起來像是我的贏家。雖然我想知道如何在OP代碼中沒有任何跟蹤時變成'#define'd。 –

+0

不,我沒有將DialogBox定義爲宏。我定義它就像一個普通的C++類。我不知道爲什麼它在同一行顯示「宏觀」警告。我向您展示的代碼是我爲DialogBox類創建的所有內容。 – TATN

+2

你是否包含Windows.h?它有一個[DialogBox](http://msdn.microsoft.com/en-gb/library/windows/desktop/ms645452%28v=vs.85%29.aspx)宏。 – Steve

相關問題