xgoan
2nd August 2006, 09:53
Hi, I'm trying to get up a class for a Qt program, but it gives me this errors:
Error 1 error C2662: 'Square::left' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
Error 2 error C2662: 'Square::up' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
Error 3 error C2662: 'Square::right' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
Error 4 error C2662: 'Square::down' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
The class code is:
Square.h:
#pragma once
#include <QPolygon>
class Square:public QPolygon{
public:
Square();
Square(const Square &rhs);
Square(const QPoint left,const QPoint up,const QPoint right,const QPoint down);
QPoint left(){return data()[left];}
QPoint up(){return data()[UP];}
QPoint right(){return data()[right];}
QPoint down(){return data()[DOWN];}
void setLeft(QPoint left);
void setUp(QPoint up);
void setRight(QPoint right);
void setDown(QPoint down);
private:
enum Points {LEFT=0,UP=1,RIGHT=2,DOWN=3};
};
Square.cpp:
#include "Square.h"
Square::Square():QPolygon(4){}
Square::Square(const Square &rhs){
Square(rhs.left(),rhs.up(),rhs.right(),rhs.down()) ;
}
Square::Square(const QPoint left,const QPoint up,const QPoint right,const QPoint down){
// Añadir los puntos dados al constructor
setPoints(4, // Número de puntos del polÃ*gono
left.x(),left.y(), // Izquierda
up.x(),up.y(), // Arriba
right.x(),right.y(), // Derecha
down.x(),down.y() // Abajo
);
}
void Square::setLeft(QPoint left){
setPoint(LEFT,left);
}
void Square::setUp(QPoint up){
setPoint(UP,up);
}
void Square::setRight(QPoint right){
setPoint(RIGHT,right);
}
void Square::setDown(QPoint down){
setPoint(DOWN,down);
}
Thank's for the help
NOTE: In lines 11, 13 appears [left] and [right] it's [L EFT] and [R IGHT] in my code. I don't know why it converts to lowercase on copy&paste.
Error 1 error C2662: 'Square::left' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
Error 2 error C2662: 'Square::up' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
Error 3 error C2662: 'Square::right' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
Error 4 error C2662: 'Square::down' : cannot convert 'this' pointer from 'const Square' to 'Square &' c:\Chus\konstructor\src\Square.cpp 6
The class code is:
Square.h:
#pragma once
#include <QPolygon>
class Square:public QPolygon{
public:
Square();
Square(const Square &rhs);
Square(const QPoint left,const QPoint up,const QPoint right,const QPoint down);
QPoint left(){return data()[left];}
QPoint up(){return data()[UP];}
QPoint right(){return data()[right];}
QPoint down(){return data()[DOWN];}
void setLeft(QPoint left);
void setUp(QPoint up);
void setRight(QPoint right);
void setDown(QPoint down);
private:
enum Points {LEFT=0,UP=1,RIGHT=2,DOWN=3};
};
Square.cpp:
#include "Square.h"
Square::Square():QPolygon(4){}
Square::Square(const Square &rhs){
Square(rhs.left(),rhs.up(),rhs.right(),rhs.down()) ;
}
Square::Square(const QPoint left,const QPoint up,const QPoint right,const QPoint down){
// Añadir los puntos dados al constructor
setPoints(4, // Número de puntos del polÃ*gono
left.x(),left.y(), // Izquierda
up.x(),up.y(), // Arriba
right.x(),right.y(), // Derecha
down.x(),down.y() // Abajo
);
}
void Square::setLeft(QPoint left){
setPoint(LEFT,left);
}
void Square::setUp(QPoint up){
setPoint(UP,up);
}
void Square::setRight(QPoint right){
setPoint(RIGHT,right);
}
void Square::setDown(QPoint down){
setPoint(DOWN,down);
}
Thank's for the help
NOTE: In lines 11, 13 appears [left] and [right] it's [L EFT] and [R IGHT] in my code. I don't know why it converts to lowercase on copy&paste.