【发布时间】:2013-08-27 20:00:01
【问题描述】:
我现在正在对 sfml 中的冲突进行测试。但是,当我运行程序时出现错误。
这是我的代码 编辑:新代码
Main.cpp
#include "Collision.h"
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML TEST");
window.setFramerateLimit(30);
sf::RectangleShape rectangle(sf::Vector2f(50, 120));
rectangle.setPosition(300, 300);
sf::View view;
view.setCenter(sf::Vector2f(300, 300));
view.setSize(sf::Vector2f(250, 250));
int moveRight = 0;
int posX;
int posY;
Collision ct();
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
//movement just right for this instance
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
moveRight = 3;
for(moveRight; moveRight > 0; moveRight--)
{
rectangle.move(1, 0);
posX = rectangle.getPosition().x;
posY = rectangle.getPosition().y;
if(ct.throneRoom(posX, posY) == true)
{
rectangle.move(1, 0);
moveRight = 0;
}
else
{
view.move(1, 0);
}
}
}
window.setView(view);
window.clear();
window.draw(rectangle);
window.display();
}
}
碰撞.h
#ifndef COLLISION_H
#define COLLISION_H
class Collision
{
public:
Collision();
bool throneRoom(int xPos, int yPos);
protected:
private:
};
#endif // COLLISION_H
碰撞.cpp
#include "Collision.h"
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
using namespace std;
Collision::Collision()
{
}
bool Collision::throneRoom(int xPos, int yPos)
{
if(xPos > 500)
return true;
else
return false;
}
我得到的错误是:
warning: error: request for member 'throneRoom' in 'ct', which is of non-class type 'Collision()'
仍然不知道发生了什么。
【问题讨论】:
-
这看起来像最麻烦的解析:en.wikipedia.org/wiki/Most_vexing_parse
-
如果没有更完整的代码,这个问题并不能真正正确回答,最好使用SSCCE,至少它还应该包括
collisiontest的声明。
标签: c++ function class collision sfml