已定义或声明"sf::Unicode::Text::text"成员函数

"sf::Unicode::Text::text" member function already defined or declared

本文关键字:Text text 函数 成员 Unicode sf 定义 声明      更新时间:2023-10-16

我最近成功地为qt-creator设置了SFML,但在编译下面的代码时,我遇到了三个奇怪的错误,这些错误与我的程序无关。我必须指定其他C++程序运行良好。这是代码:

#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;
}

错误如下:

f:SFML-1.6includeSFMLSystemUnicode.hpp:82: error: C2535: 'sf::Unicode::Text::Text(const wchar_t *)' : member function already defined or declared
f:SFML-1.6includeSFMLSystemUnicode.hpp:87: error: C2535: 'sf::Unicode::Text::Text(const std::wstring &)' : member function already defined or declared
f:SFML-1.6includeSFMLSystemUnicode.hpp:99: error: C2535: 'sf::Unicode::Text::operator std::wstring(void) const' : member function already defined or declared

知道是什么原因造成的吗?

编辑:

我还应该提到,我从未接触过出现错误的文件。我所尝试的只是粘贴SFML网站上的示例代码,这导致了上面的错误。我相信我已经正确地设置了SFML。

第2版:我使用的是Windows XP SP3,Mingw编译器

我很久以前就遇到过这个问题,唯一对我有效的解决方案和解释(复制自我最初咨询的另一个论坛帖子):

QMake将编译器选项treat wchar_t as a built-in type设置为false,使wchar_t成为unsigned short的typedef,使对于unsigned shortwchar_t都过载的函数(如sf::Unicode::Text构造函数)失败。。。

我认为除了修改SFML源之外,唯一的解决方案是在\mkspecs\win32-msvc2008\qmake.conf文件。然后可能重新编译Qt。

我更改了配置文件并重新编译了qt,它已经开始发挥魅力了。

根据http://msdn.microsoft.com/en-us/library/dh8che7s%28v=vs.80%29.aspx

如果指定了/Zc:wchar_t-,编译器要求您定义wchar_t或包含定义它的许多头文件中的一个(例如wchar.h)。通常,wchar_t被定义为无符号短

在Visual Studio开发环境中设置此编译器选项

Open the project's Property Pages dialog box. For details, see Modifying Project Settings.
Click the C/C++ folder.
Click the Language property page.
Modify the Treat wchar_t as Built-in Type property.

所以问题是在Config.hpp 中

typedef unsigned short Uint16;

并且有了这个/Zc:wchar_t选项,wchar_

typedef unsigned short wchar_t;

所以它们等于