Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] cannot compile; no match for operators '<' and '  (Read 3062 times)

0 Members and 1 Guest are viewing this topic.

pyronide

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SOLVED] cannot compile; no match for operators '<' and '
« on: March 17, 2012, 07:55:22 am »
Hello!

I am relatively new to C++ and sfml, so this question might be obvious to some:

I am attempting to build the following:
Code: [Select]
#include<SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock Clock;
    while(Clock.getElapsedTime() < 5.f)
    {
        std::cout << Clock.getElapsedTime() << std::endl;
        sf::sleep(0.5f);
    }

    return 0;
}


and I recieve compiler errors, telling me that it cannot find a match for an operater that takes a float as an argument: specifically:
Code: [Select]

/data/workspace/SFML-Sandbox/main.cpp:7:36: error: no match for ‘operator<’ in ‘Clock.sf::Clock::getElapsedTime() < 5.0e+0f’
/data/workspace/SFML-Sandbox/main.cpp:7:36: note: candidates are:
/usr/include/SFML/System/String.hpp:440:22: note: bool sf::operator<(const sf::String&, const sf::String&)
/usr/include/SFML/System/String.hpp:440:22: note:   no known conversion for argument 1 from ‘sf::Time’ to ‘const sf::String&’
/usr/include/SFML/System/Time.hpp:185:22: note: bool sf::operator<(sf::Time, sf::Time)
/usr/include/SFML/System/Time.hpp:185:22: note:   no known conversion for argument 2 from ‘float’ to ‘sf::Time’

and
Code: [Select]

/data/workspace/SFML-Sandbox/main.cpp:9:43: error: no match for ‘operator<<’ in ‘std::cout << Clock.sf::Clock::getElapsedTime()’


I have tried compiling this from both code::blocks and eclipse, as well as the command line - for both IDEs, I am using the defaults(as per the archlinux official repos), only ensuring that the appropriate libraries are listed - although I am not even getting object code to link!  I have also tried both the git snapshot, the 1.6 version from AUR, and the archlinux community repos.


are there any additional steps I need to take when compiling?


if so, how would I propose an edit to the tutorial? (it doesn't mention any specific steps for compilation.)

thank you for your time!

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
[SOLVED] cannot compile; no match for operators '<' and '
« Reply #1 on: March 17, 2012, 08:32:32 am »
I see you are using the current SFML 2 release. Recently the getElapsedTime was changed, and its return is now a sf::Time variable. If you want to do math with it, first call .asSeconds(), .asMilliseconds() or .asMicroseconds().

The sleep function was also altered so that it receive a sf::Time object as parameter, instead of float.

I think you want something like this:

Code: [Select]
#include<SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock Clock;
    while(Clock.getElapsedTime().asSeconds() < 5.f)
    {
        std::cout << Clock.getElapsedTime().asSeconds() << std::endl;
        sf::sleep(sf::seconds(0.5f));
    }

    return 0;
}

pyronide

  • Newbie
  • *
  • Posts: 4
    • View Profile
[SOLVED] cannot compile; no match for operators '<' and '
« Reply #2 on: March 17, 2012, 06:34:55 pm »
thanks! that did the trick!