简体   繁体   English

C ++-错误C4430:缺少类型说明符(用于构造函数???)

[英]C++ - Error C4430: missing type specifier (for a constructor???)

I've been stuck with this since last night, and for the life of me, I haven't been able to figure out why this is happening. 从昨晚开始,我就一直坚持这一点,对于我的一生,我一直无法弄清为什么会这样。 I must be missing something very simple. 我一定会错过一些非常简单的东西。

I'm making an OpenGL program. 我正在制作OpenGL程序。 In this program, I'm making a DialogBox class. 在此程序中,我正在制作DialogBox类。 Below is the code: 下面是代码:

//---------------------------------------------------------------
//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();
}

And the compiler threw this error message: 然后编译器抛出此错误消息:

在此处输入图片说明

I have been pulling my hairs out, but I couldn't figure out what the compiler were referring to. 我一直在努力,但是我不知道编译器在指什么。 It must be something really simple (like a typo in the codes or something like that). 它必须非常简单(例如代码中的错字或类似的东西)。 Thank you in advance for your help. 预先感谢您的帮助。

What's that warning on the same line? 同一行上的警告是什么?

not enough actual parameters for macro 'DialogBoxA' 宏“ DialogBoxA”的实际参数不足

Is DialogBox a #define -d macro? DialogBox#define -d宏吗? If so, that would probably mess things up. 如果是这样,那可能会使事情变得混乱。

When I compile your code, I get an error on DialogBox::draw() , because you're not specifying the return type there. 编译代码时, DialogBox::draw()出现错误,因为您未在此处指定返回类型。 Specifically, this is on the implementation, not the declaration. 具体来说,这是在实现上,而不是在声明上。 That's the only compiler error I find in your code. 那是我在您的代码中发现的唯一编译器错误。 Perhaps your compiler is just flagging the wrong line? 也许您的编译器只是在标记错误的行?

Microsoft already provides a function (macro?) with the name DialogBox: http://msdn.microsoft.com/en-us/library/windows/desktop/ms645452%28v=vs.85%29.aspx Microsoft已经提供了一个名称为DialogBox的函数(宏?): http : //msdn.microsoft.com/zh-cn/library/windows/desktop/ms645452%28v=vs.85%29.aspx

It probably got pulled in by <iostream> , <vector> or whatever. 它可能被<iostream><vector>或其他任何东西所吸引。 Renaming your class to a more original name should help. 将班级重命名为更原始的名称应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM