首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++编译错误,构造函数没有返回类型...但是我没有指定一个

C++编译错误,构造函数没有返回类型...但是我没有指定一个
EN

Stack Overflow用户
提问于 2011-04-18 19:46:48
回答 4查看 10K关注 0票数 9

下面是错误: 1>c:\users\ben\documents\visual studio 2010\projects\opengl_learning\opengl_learning_without_glut\openglcontext.cpp(18):error C2533:'OpenGLContext::{ctor}‘:构造函数不允许返回类型

下面是错误所在的代码块,特别是错误来自默认构造函数:

代码语言:javascript
复制
#include <Windows.h>
#include <iostream>
#include "OpenGLContext.h"


/**
    Default constructor for the OpenGLContext class. At this stage it does nothing 
    but you can put anything you want here. 
*/
OpenGLContext::OpenGLContext(void){}
OpenGLContext::OpenGLContext(HWND hwnd) { 
    createContext(hwnd); 
}
/** 
    Destructor for our OpenGLContext class which will clean up our rendering context 
    and release the device context from the current window. 
*/  

OpenGLContext::~OpenGLContext(void) { 
    wglMakeCurrent(hdc, 0); // Remove the rendering context from our device context
    wglDeleteContext(hrc); // Delete our rendering context 
    ReleaseDC(hwnd, hdc); // Release the device context from our window
}

为什么!?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-04-18 19:48:54

很可能您在OpenGLContext的定义之后忘记了一个分号。

代码语言:javascript
复制
class OpenGLContext { /* ... */ } OpenGLContext::OpenGLContext(void) { }

这在语法上是有效的。但是由于构造函数没有返回类型,正如消息所说的那样,编译器会抱怨。

票数 28
EN

Stack Overflow用户

发布于 2011-04-18 19:49:41

头文件中类定义后缺少分号

票数 6
EN

Stack Overflow用户

发布于 2011-04-18 19:51:19

打开文件OpenGLContext.h,并确保在OpenGLContext类定义后放置了分号。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5702342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档