mf_2
2010-03-15, 22:32:15
Hallo zusammen,
im C++ Kurs an der Hochschule haben wir heute ein Programm erstellt, welches uns das Konzept der Objektorientierung in dieser Sprache zeigen soll. Es hat folgende Dateien:
Rectangle.h
class CRectangle
{
// standardmäßig: private
unsigned short x, y;
unsigned short width, height;
public: // damit von außen zugreifbar
void SetPos(unsigned short x, unsigned short y);
void SetDim(unsigned short width, unsigned short length);
unsigned int GetArea();
}
Rectangle.cpp
#include "Rectangle.h"
void CRectangle::SetPos(unsigned short x, unsigned short y)
{
this->x = x;
this->y = y;
}
void CRectangle::SetDim(unsigned short width, unsigned short length)
{
this->width = width;
this->height = height;
}
unsigned int CRectangle::GetArea()
{
return this->height*this->width;
}
main.cpp:
#include "Rectangle.h"
#include <iostream>
using namespace std;
int main()
{
CRectangle myRect;
myRect.SetPos(1, 1);
myRect.SetDim(2, 3);
cout << "Flaecheninhalt: " << myRect.GetArea() << endl;
system("pause");
return 0;
}
So weit sieht das eigentlich alles ganz gut aus, aber beim Compilieren in Visual Studio bekomme ich immer folgende Fehler:
c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2628: 'CRectangle' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2628: 'CRectangle' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2347: '__w64' : can not be used with type '__w64 CRectangle'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2371: 'size_t' : redefinition; different basic types
1> c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\predefined c++ types (compiler internal)(19) :
see declaration of 'size_t'
1>Rectangle.cpp
1>c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.cpp(5) :
error C2628: 'CRectangle' followed by 'void' is illegal (did you forget a ';'?)
1>c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.cpp(6) :
error C2556: 'CRectangle CRectangle::SetPos(unsigned short,unsigned short)' :
overloaded function differs only by return type from 'void CRectangle::SetPos(unsigned short,unsigned short)'
1> c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.h(10) :
see declaration of 'CRectangle::SetPos'
1>c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.cpp(6) :
error C2371: 'CRectangle::SetPos' : redefinition; different basic types
1> c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.h(10) :
see declaration of 'CRectangle::SetPos'
Ich habe die Schuld zuerst auf die Beta von Visual Studio 2010 geschoben und nun extra das VS 2008 installiert, aber die Fehler sind nach wie vor da. Der Error-Log ist aus dem VS 2008.
Was mache ich da falsch?
Und warum meckert er in einer sourceannotations-Datei? Das ist ja nicht eine von mir erzeugte Datei.
Gruß,
mf_2
im C++ Kurs an der Hochschule haben wir heute ein Programm erstellt, welches uns das Konzept der Objektorientierung in dieser Sprache zeigen soll. Es hat folgende Dateien:
Rectangle.h
class CRectangle
{
// standardmäßig: private
unsigned short x, y;
unsigned short width, height;
public: // damit von außen zugreifbar
void SetPos(unsigned short x, unsigned short y);
void SetDim(unsigned short width, unsigned short length);
unsigned int GetArea();
}
Rectangle.cpp
#include "Rectangle.h"
void CRectangle::SetPos(unsigned short x, unsigned short y)
{
this->x = x;
this->y = y;
}
void CRectangle::SetDim(unsigned short width, unsigned short length)
{
this->width = width;
this->height = height;
}
unsigned int CRectangle::GetArea()
{
return this->height*this->width;
}
main.cpp:
#include "Rectangle.h"
#include <iostream>
using namespace std;
int main()
{
CRectangle myRect;
myRect.SetPos(1, 1);
myRect.SetDim(2, 3);
cout << "Flaecheninhalt: " << myRect.GetArea() << endl;
system("pause");
return 0;
}
So weit sieht das eigentlich alles ganz gut aus, aber beim Compilieren in Visual Studio bekomme ich immer folgende Fehler:
c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2628: 'CRectangle' followed by 'unsigned' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2628: 'CRectangle' followed by 'int' is illegal (did you forget a ';'?)
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2347: '__w64' : can not be used with type '__w64 CRectangle'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) :
error C2371: 'size_t' : redefinition; different basic types
1> c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\predefined c++ types (compiler internal)(19) :
see declaration of 'size_t'
1>Rectangle.cpp
1>c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.cpp(5) :
error C2628: 'CRectangle' followed by 'void' is illegal (did you forget a ';'?)
1>c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.cpp(6) :
error C2556: 'CRectangle CRectangle::SetPos(unsigned short,unsigned short)' :
overloaded function differs only by return type from 'void CRectangle::SetPos(unsigned short,unsigned short)'
1> c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.h(10) :
see declaration of 'CRectangle::SetPos'
1>c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.cpp(6) :
error C2371: 'CRectangle::SetPos' : redefinition; different basic types
1> c:\...\visual studio 2008\projects\dhbw übungen 1\dhbw übungen 1\rectangle.h(10) :
see declaration of 'CRectangle::SetPos'
Ich habe die Schuld zuerst auf die Beta von Visual Studio 2010 geschoben und nun extra das VS 2008 installiert, aber die Fehler sind nach wie vor da. Der Error-Log ist aus dem VS 2008.
Was mache ich da falsch?
Und warum meckert er in einer sourceannotations-Datei? Das ist ja nicht eine von mir erzeugte Datei.
Gruß,
mf_2