什么是错误:‘(’标记之前预期有不合格的 id?

问题描述 投票:0回答:1

我克隆了这个开源项目https://github.com/balfieri/cordic。按照 README 运行后,我遇到了以下问题

$ g++ -std=c++17 -o test_basic test_basic.cpp

$ g++ -std=c++17 -o test_basic test_basic.cpp
In file included from /usr/include/c++/11/cmath:45,
                 from Cordic.h:24,
                 from freal.h:43,
                 from test_basic.cpp:23:
Cordic.h:152:10: error: expected ‘)’ before ‘==’ token
  152 |     bool issubnormal( const T& x ) const;                               // fpclassify() is FP_SUBNORMAL
      |          ^~~~~~~~~~~
Cordic.h:2319:28: error: expected unqualified-id before ‘(’ token
 2319 | inline bool Cordic<T,FLT>::issubnormal( const T& x ) const
      |                            ^~~~~~~~~~~
In file included from freal.h:43,
                 from test_basic.cpp:23:
Cordic.h: In instantiation of ‘Cordic<T, FLT>::Cordic(uint32_t, uint32_t, bool, uint32_t, uint32_t) [with T = long int; FLT = double; uint32_t = unsigned int]’

https://github.com/balfieri/cordic/blob/master/Cordic.h#L152

bool issubnormal( const T& x ) const;

https://github.com/balfieri/cordic/blob/master/Cordic.h#L2318

template< typename T, typename FLT >
inline bool Cordic<T,FLT>::issubnormal( const T& x ) const                                     
{
    return fpclassify( x ) == FP_SUBNORMAL;
}

我不知道为什么会发生错误,因为我认为没有语法错误。 如果有人能告诉我如何解决它,我将不胜感激。

c++ c++17
1个回答
0
投票

如果有人能告诉我如何解决它,我将不胜感激。

您可以通过在成员函数的声明周围添加括号来解决此问题,使其与同名的宏不同,如下所示:

template<typename T> struct Cordic
{
    //---vvvvvvvvvvvv------->added parenthesis here
    bool (issubnormal)( const T& x ) const;
};
template< typename T>
//----------vvvvvvvvvvvvvvvvvvvvvvv----------->added parenthesis here
inline bool (Cordic<T>::issubnormal)( const T& x ) const                                     
{
    return {};
}
© www.soinside.com 2019 - 2024. All rights reserved.