I have the following class:
GLRectangle.h
#include "XPView.h"
class GLRectangle
{
public:
int top, left, bottom, right;
public:
GLRectangle(void);
~GLRectangle(void);
GLRectangle* centerRect(int rectWidth, int rectHeight, int boundWidth=0, int boundHeight=0);
};
GLRectangle.cpp
#include "GLRectangle.h"
GLRectangle::GLRectangle(void)
{
}
GLRectangle::~GLRectangle(void)
{
}
GLRectangle* GLRectangle::centerRect(int rectWidth, int rectHeight, int boundWidth, int boundHeight)
{
if(boundWidth == 0)
{
boundWidth = XPView::getWindowWidth();
}
if(boundHeight == 0)
{
boundHeight = XPView::getWindowHeight();
}
// Set rectangle attributes
left = boundWidth / 2 - rectWidth / 2;
top = boundHeight / 2 + rectHeight / 2;
right = boundWidth / 2 + rectWidth / 2;
bottom = boundHeight / 2- rectHeight / 2;
return this;
}
and I’m trying to chain a function onto the construction of the object as follows:
wndRect = new GLRectangle()->centerRect(400, 160);
but getting the following error:
error C2143: syntax error:missing ';' before '->'
Is there a way to get this to work?
It’s an operator precedence problem. Try