Expected unqualified-id before ‘unsigned’

Hi, I am new to C++ programming and have been studying it for about a week. I have run into a few problems, like all beginners, but have always been able to figure them out until now.The program I am stuck on is as follows:


#include <iostream>

class Rectangle {

unsigned width, unsigned height;

void set_size(unsigned x, unsigned y);
unsigned area();
unsigned perimeter();
bool is_square();
}; //end of of class Rectangle

void Rectangle::set_size(unsigned x, unsigned y) {
width = x;
height = y;

unsigned Rectangle::area();
return (width * height);

unsigned Rectangle::perimeter();
return ( (width * 2) + (height * 2) );

bool Rectangle::is_square();
if (width == height);{
return true;
} else {
return false;

int main(){
unsigned width = 25;
unsigned height = 14;

std::cout << "With a width of " << width << " and a height of " << height << "...\n\n";

std::cout << "Press Enter to continue...";

return 0;
} //end of main

And the the primary error message (which I suspect to be the root cause for all the subsequent ones) is this:

rectangle-02.cpp:8: error: expected unqualified-id before ‘unsigned’

I've scowred the internet for this error but so far all I've learned is that you could get this error if you leave out a colon before specifying a class method or add an extraneous '()' after a class definition, neither of which are the problem here. I have gone over the code again and again and it seems to be identical to what is written in the book I am copying it from. The only conclusion I can come to is that there must be something wrong with my compiler -though it has worked just fine until now.

If it helps I am using the GNU C++ Compiler v 4.1 (the latest version) on a Debian Linux box.I would try another compiler if I could, but I can't find anything in the Debian libraries and I'm a little afraid to try anything that hasn't been approved.
Last edited on
You are missing quite a few braces. You need to close else statements when you open them, close function definitions, and define functions outside of other function bodies.

For example, you have something like:
void func1() {
    //... code

    void func2(); // You cannot define another function here, inside of another
        return someVal; // You need to enclose this function body in braces anyway
    if(/*...*/) {
    } else {

//You need to end the definition of func1()!


EDIT: I rethought my response: You are missing a lot of braces. When you open any function, you need to close it. You also need to open functions when you are defining them.

e.g. the following is incorrect:
void Rectangle::set_size(unsigned x, unsigned y) {
    width = x;
    height = y;
// You need to end set_size() using a } 
Last edited on
remove the second unsigned on line 8 of rectangle-02.cpp: unsigned width, unsigned height; or change the , to a ;
unsigned width; unsigned height;

Last edited on
Thanks to both Zhuge and Grey Wolf, I rewrote it from scratch and got it to compile. Not only was I missing braces, I also had semicolons where they did not belong (like after the method statements). Learning C++ was easy until I got to the chapter on OOP which is an entirely new concept for me. Thank you again for your help.
Topic archived. No new replies allowed.