acp10bda
acp10bda

Reputation: 301

C++ compilation error, constructor has no return type... but I didn't specify one

So here is the error: 1>c:\users\ben\documents\visual studio 2010\projects\opengl_learning\opengl_learning_without_glut\openglcontext.cpp(18): error C2533: 'OpenGLContext::{ctor}' : constructors not allowed a return type

And here is a block of code where the error points, specifically the error originates from the default constructor:

#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
}

Why!?

Upvotes: 11

Views: 13064

Answers (4)

Mayank Pathela
Mayank Pathela

Reputation: 648

The class definition should have a semicolon at the end.

Upvotes: 2

Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361812

Open the file OpenGLContext.h and make sure if you've put semicolon after OpenGLContext class definition.

Upvotes: 2

fizzer
fizzer

Reputation: 13806

Missing semicolon after the class definition in the header file

Upvotes: 8

Johannes Schaub - litb
Johannes Schaub - litb

Reputation: 507433

Most likely you forgot a semicolon after OpenGLContext's definition. Then your code is parsed as

class OpenGLContext { /* ... */ } OpenGLContext::OpenGLContext(void) { }

That's valid syntactically. But as constructors don't have a return type, like the message says, the compiler complains.

Upvotes: 32

Related Questions