gpt4 book ai didi

c++ - 错误 : expected unqualified-id before '<' token|

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:38 24 4
gpt4 key购买 nike

我收到以下错误:

preprocessor_directives.cpp|15|error: expected unqualified-id before '<' token|
preprocessor_directives.cpp|26|error: expected `;' before "int"|
||=== Build finished: 2 errors, 0 warnings ===|
#include <iostream>

using namespace std;

// Avoid. Using #define for constants
#define MY_CONST1 1000

// Use. Equivalent constant definition
const int MY_CONST2 = 2000;

// Avoid. Using #define for function like macros
#define SQR1(x) (x*x)

// Use. Equivalent function definition
inline template <typename T>
T SQR2 ( T a ) {
return a*a;
}
// Writing #define in multiple lines
#define MAX(a,b) \
((a) > (b) ? (a) : (b))

// Compile time flags
#define DEBUG

int main()
{
cout << "SQR1 = " << SQR1(10) << endl;
cout << "SQR2 = " << SQR2(10) << endl;
cout << "MAX = " << MAX(10,11) << endl;
cout << "MY_CONST1 = " << MY_CONST1 << endl;
cout << "MY_CONST2 = " << MY_CONST2 << endl;

return 0;
}

最佳答案

inline 关键字移到 template 关键字之后。

template <typename T> inline
T SQR2 ( T a ) {
return a*a;
}

关于c++ - 错误 : expected unqualified-id before '<' token|,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6438563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com