Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class Trouble 1

Status
Not open for further replies.

fugigoose

Programmer
Jun 20, 2001
241
US
I'm trying to write a class for my program. It keeps telling me that 'constructors aren't allowed return types". I know this, and my constructor doesnt return anything. What am I doing wrong? I did it EXACTLY how the book said to. Here's the class definition:

class ctl_button{
public:
int x;
int y;
int width;
int height;
char caption [100];
bool enabled;
long action;
COLORREF backColor;
COLORREF foreColor;

ctl_button();
draw(HDC hdc);
}


ctl_button::ctl_button(){
x = 0;
y = 0;
width = 0;
height = 0;
enabled = 1;
action = NULL;
}

ctl_button::draw(HDC hdc){
HPEN pen = CreatePen(PS_SOLID, 1, RGB(100, 100, 100));
SelectObject(hdc, pen);
Rectangle(hdc, x, y, x + width, x + height);
}


By the way, is there a way to have a char array that has no set dimensions? The caption property I kind of would like to be able to set it to any string I want....C++ makes this very hard.
 
You forgot a semicolon after the class declaration, so the parser treats that entire class as the return type for the constructor that follows.

C++ makes it easy to have a string of any length. Use a string obect (std::string in header <string>) instead of a char array. It'll manage itself for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top