C ++错误:'inline'只能出现在函数上 [英] C++ error: 'inline' can only appear on functions

查看:2191
本文介绍了C ++错误:'inline'只能出现在函数上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用clang ++在OS X 10.7下编译 VCMI



我配置项目与 CXX = clang ++ 因为苹果的gcc似乎不认识所需 -std =



我添加了 -stdlib = libc ++ CXXFLAGS 因为没有那个clang甚至不能找到 #include< array>



目前我有: CXXFLAGS = -std = c ++ 0x -stdlib = libc ++ -Wall -Wextra -Wcast-align -Wpointer -arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wc ++ 11-extensions



我收到以下错误:

  clang:warning:将'c-header'输入为'c ++  - 模式,此行为已过时
clang:warning:参数在编译期间未使用:'-ggdb'
StdInc.h:1:9:warning:#pragma once in main file
#pragma once
^
在从StdInc.h中包含的文件中:3:
从./../Global.h:32:
中包含的文件在/ usr / bin中包含的文件/../lib/c++/v1/algorithm:594:
在/usr/bin/../lib/c++/v1/memory:596:
/ usr / bin /中包含的文件中。 ./lib/c++/v1/iterator:1696:1:错误:'inline'只能出现在函数
inline _LIBCPP_INLINE_VISIBILITY
^
/usr/bin/../lib/c++ / v1 / iterator:1698:1:error:变量'begin'声明为模板
begin(_T(& __ array)[_ N])
^
/ usr / bin /。 ./lib/c++/v1/iterator:1698:12:error:使用未声明的标识符'__array'
begin(_T(& __ array)[_ N])
^
./ ../tchar_amigaos4.h:157:16:note:从宏'_T'扩展
#define _T(x)x
^
在从StdInc.h中包含的文件中:3:
在./../Global.h:32中包含的文件中:
在/usr/bin/../lib/c++/v1/algorithm:594中包含的文件中:
在文件中包括从/usr/bin/../lib/c++/v1/memory:596:
/usr/bin/../lib/c++/v1/iterator:1698:25:error:expected';'在结束声明
begin(_T(& __ array)[_ N])
^
;
/usr/bin/../lib/c++/v1/iterator:1699:1:error:expected unqualified-id
{
^
1个警告和5个错误。

我必须承认,我从来没有见过这样的事情。这些都在libc ++源代码!

解决方案

您的问题在这里:

  ./../ tchar_amigaos4.h:157:16:注意:从宏_T扩展
#define _T(x)x

在代码中定义一个名为_T的宏,然后包含标准头,这是一个未定义的行为,严格来说。 / p>

IIRC,libc ++的较新版本避免使用名称_T,特别是因为人们倾向于使用这个名称,因此您可能想尝试升级到最新版本的命令行工具。


I'm trying to compile VCMI under OS X 10.7 using clang++.

I configured project with CXX=clang++ because Apple's gcc didn't seem to recognize required -std=c++0x flag.

I've added -stdlib=libc++ to CXXFLAGS because without that clang wasn't even able to find #include <array>.

Currently i've got: CXXFLAGS= -std=c++0x -stdlib=libc++ -Wall -Wextra -Wcast-align -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wc++11-extensions

The problem is that I get following errors:

clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior    is deprecated
clang: warning: argument unused during compilation: '-ggdb'
StdInc.h:1:9: warning: #pragma once in main file
#pragma once
        ^
In file included from StdInc.h:3:
In file included from ./../Global.h:32:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In file included from /usr/bin/../lib/c++/v1/memory:596:
/usr/bin/../lib/c++/v1/iterator:1696:1: error: 'inline' can only appear on functions
inline _LIBCPP_INLINE_VISIBILITY
^
/usr/bin/../lib/c++/v1/iterator:1698:1: error: variable 'begin' declared as a template
begin(_T (&__array)[_N])
^
/usr/bin/../lib/c++/v1/iterator:1698:12: error: use of undeclared identifier '__array'
begin(_T (&__array)[_N])
           ^
./../tchar_amigaos4.h:157:16: note: expanded from macro '_T'
#define _T(x)           x
                        ^
In file included from StdInc.h:3:
In file included from ./../Global.h:32:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In file included from /usr/bin/../lib/c++/v1/memory:596:
/usr/bin/../lib/c++/v1/iterator:1698:25: error: expected ';' at end of declaration
begin(_T (&__array)[_N])
                        ^
                        ;
/usr/bin/../lib/c++/v1/iterator:1699:1: error: expected unqualified-id
{
^
1 warning and 5 errors generated.

I must admit that I've never saw anything like this. These are in libc++ sources! Does anybody know what may be the cause?

解决方案

Your issue is here:

./../tchar_amigaos4.h:157:16: note: expanded from macro '_T'
#define _T(x)           x

Defining a macro named _T in your code, then including standard headers, is undefined behavior, strictly speaking.

IIRC, newer versions of libc++ avoid the use of the name _T in particular because people tend to screw this up, so you might want to try upgrading to the newest version of the command-line tools.

这篇关于C ++错误:'inline'只能出现在函数上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆