Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: expected unqualified-id before '<' token|

Tags:

c++

I'm getting the following errors:

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;
}
like image 944
pandoragami Avatar asked Jun 22 '11 10:06

pandoragami


People also ask

How do you fix expected unqualified ID before token?

– Adjust the Curly Braces To Fix the Expected Unqualified Id Error. You should match the opening and closing curly braces in your code to ensure the right quantity of brackets. The code should not have an extra or a missing curly bracket.

What is expected unqualified ID before if?

The error is occurring because you have 2 if statements outside of a function. You could move them into the ping() function which would fix the error but there seems to be a logic error with the 2 if statements as well.

What is an expected identifier in C?

In C, an identifier is expected in the following situations: in a list of parameters in an old-style function header. after the reserved words struct or union when the braces are not present, and. as the name of a member in a structure or union (except for bit fields of width 0).


2 Answers

Move the inline keyword after the template keyword.

template <typename T> inline
T SQR2 ( T a ) {
    return a*a;
}
like image 150
Mat Avatar answered Sep 24 '22 20:09

Mat


template <typename T>
inline T SQR2 ( T a ) {
    return a*a;
}
like image 43
Karoly Horvath Avatar answered Sep 24 '22 20:09

Karoly Horvath