【问题标题】:error C2084: function 'float cbrt(float) throw()' already has a body错误 C2084:函数 'float cbrt(float) throw()' 已经有一个主体
【发布时间】:2015-08-03 09:24:10
【问题描述】:

我在visual studio 2010平台下成功编译了这个项目,但是在vs 2013中出现了这些错误:

 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(1045) : see previous definition of 'cbrt'
d:\documents\qtprojecttest\rtsc\project4\trimesh2\include\Vec.h(657) : error C2084: function 'long double cbrt(long double) throw()' already has a body
 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(1161) : see previous definition of 'cbrt'
d:\documents\qtprojecttest\rtsc\project4\trimesh2\include\Vec.h(664) : error C2084: function 'float round(float) throw()' already has a body
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(1125) : see previous definition of 'round'
d:\documents\qtprojecttest\rtsc\project4\trimesh2\include\Vec.h(672) : error C2084: function 'long double round(long double) throw()' already has a body
 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(1241) : see previous definition of 'round'
d:\documents\qtprojecttest\rtsc\project4\trimesh2\include\Vec.h(679) : error C2084: function 'float trunc(float) throw()' already has a body
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(1143) : see previous definition of 'trunc'
d:\documents\qtprojecttest\rtsc\project4\trimesh2\include\Vec.h(687) : error C2084: function 'long double trunc(long double) throw()' already has a body

我想知道为什么会有这样的差异,以及如何解决?

【问题讨论】:

  • 似乎标准数学和Vec.h 之间存在冲突。你在那里重新定义标准功能吗?你有包括后卫吗?还是包含在自己的命名空间中?
  • 您基本上发现了为什么微软这么长时间都避免支持 C99。它将一堆简短的通用名称转储到全局命名空间中,非常难以处理。但他们无法再避免它了,C++11 要求它。因此,粗略地说,您自己的缺少 C99 函数的解决方法不再合适。删除它们。输出窗口显示它们的定义位置。

标签: c++ visual-studio-2010 visual-studio-2012


【解决方案1】:

为什么VS2010和VS2013有这么大的区别?因为VS2010没有“cbrt”的定义,而Vs2013有。所以可以使用_MSC_VER,或者直接在Vec.h中注释repeat函数体。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 2017-07-06
    • 1970-01-01
    相关资源
    最近更新 更多