I wrote a simple function to draw a rectangle. Everything is fine except I have 2 small (i think) errors. I just can't figure out what I'm doing wrong...
#include <iostream>
usingnamespace std;
class rechthoek
{
private:
int hoogte;
int breedte;
public:
rechthoek (int b = 0, int h = 0) : breedte(b), hoogte(h){}
void print();
//getters & setters
int getHoogte()
{
return hoogte;
}
int getBreedte()
{
return breedte;
}
void setHoogte(int h)
{
hoogte = h;
}
void setBreedte(int b)
{
breedte = b;
}
}
int main()
{
int h, b;
rechthoek rechthoek1;
//set hoogte
cout<<"Hoe hoog moet de rechthoek zijn?\n";
cin>>h;
rechthoek1::setHoogte(h);
//set breedte
cout<<"Hoe breed moet de rechthoek zijn?\n";
cin>>b;
rechthoek1::setBreedte(b);
rechthoek1::print();
void rechthoek::print()
{
//bovenste lijn
for (int i = 0; i < rechthoek1::getBreedte(); ++i)
{
cout<<"x";
}
cout<<"\n";
//middenstuk
for (int j = 0; j < rechthoek1::getHoogte() - 2; ++j)
{
cout<<"x";
for(int k = 0; k < rechthoek1::getBreedte() - 2; ++k)
{
cout<<" ";
}
cout<<"x";
cout<<"\n";
}
//bovenste lijn
for (int i = 0; i < rechthoek1::getBreedte(); ++i)
{
cout<<"x";
}
}
}
And here's the error I'm getting:
1 2 3 4 5 6 7 8
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp||In constructor 'rechthoek::rechthoek(int, int)':|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|9|warning: 'rechthoek::breedte' will be initialized after|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|8|warning: 'int rechthoek::hoogte'|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|12|warning: when initialized here|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|5|error: new types may not be defined in a return type|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|5|note: (perhaps a semicolon is missing after the definition of 'rechthoek')|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|38|error: two or more data types in declaration of 'main'|
||=== Build finished: 2 errors, 3 warnings ===|
Oh god, english is not my native language and i thought semicolon meant: { instead of ; :p
But now I have these other errors:
1 2 3 4 5 6 7 8 9 10 11 12
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp||In constructor 'rechthoek::rechthoek(int, int)':|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|9|warning: 'rechthoek::breedte' will be initialized after|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|8|warning: 'int rechthoek::hoogte'|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|12|warning: when initialized here|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp||In function 'int main()':|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|46|error: 'rechthoek1' is not a class or namespace|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|51|error: 'rechthoek1' is not a class or namespace|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|53|error: 'rechthoek1' is not a class or namespace|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|61|error: 'rechthoek1' is not a class or namespace|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|62|error: a function-definition is not allowed here before '{' token|
C:\Documents and Settings\XAN DIET VINIE\My Documents\XANDER\Programmeren\Boek Opgave 9.10 [1]\main.cpp|94|error: expected '}' at end of input|
||=== Build finished: 6 errors, 3 warnings ===|