errorc2059:syntaxerror:'...'是什么意思
答案:2 悬赏:80
解决时间 2021-01-19 22:53
- 提问者网友:最美的风景
- 2021-01-19 11:49
errorc2059:syntaxerror:'...'是什么意思
最佳答案
- 二级知识专家网友:而你却相形见绌
- 2019-10-29 13:53
Compiler Error C2059
Error Message
syntax error : 'token'
The token caused a syntax error.
To
determine the cause, examine not only the line listed in the error
message, but also the lines above it. The following example generates an
error message for the line declaring j, but the true source of the error appears on the line just above it.
If
examining the lines yields no clue to what the problem might be, try
commenting out the line listed in the error message and possibly several
lines above it.
If the error message occurs on a symbol immediately following a typedef variable, check that the variable is defined in the source code.
You may get C2059 if a symbol evaluates to nothing, as can occur when you compile with /Dsymbol=.
// C2059a.cpp
// compile with: /DTEST=
#include <stdio.h>
int main() {
#ifdef TEST
printf_s("\nTEST defined %d", TEST); // C2059
#else
printf_s("\nTEST not defined");
#endif
}
Another specific reason you can get C2059 is when you compile an
application that specifies a structure in the default arguments for a
function. The default value for an argument must be an expression. An
initializer list, such as that used to initialize a structure, is not an
expression. The resolution is to define a constructor to perform the
required initialization.
The following example generates C2059:
// C2059b.cpp
// compile with: /c
struct ag_type {
int a;
float b;
// Uncomment the following line to resolve.
// ag_type(int aa, float bb) : a(aa), b(bb) {}
};
void func(ag_type arg = {5, 7.0}); // C2059
void func(ag_type arg = ag_type(5, 7.0)); // OK
You can also get C2059 if you define a member template class or
function outside the class. See Knowledge Base article Q241949 for more
information.
C2059 can occur for an ill-formed cast.
The following sample generates C2059:
// C2059c.cpp
// compile with: /clr
using namespace System;
ref class From {};
ref class To : public From {};
int main() {
From^ refbase = gcnew To();
To^ refTo = safe_cast<To^>(From^); // C2059
To^ refTo2 = safe_cast<To^>(refbase); // OK
}
C2059 can also occur if you attempt to create a namespace name that contains a period.
The following sample generates C2059:
// C2059d.cpp
// compile with: /c
namespace A.B {} // C2059
// OK
namespace A {
namespace B {}
}
C2059 can also occur if you define a member template class or function outside the class.
Error Message
syntax error : 'token'
The token caused a syntax error.
To
determine the cause, examine not only the line listed in the error
message, but also the lines above it. The following example generates an
error message for the line declaring j, but the true source of the error appears on the line just above it.
If
examining the lines yields no clue to what the problem might be, try
commenting out the line listed in the error message and possibly several
lines above it.
If the error message occurs on a symbol immediately following a typedef variable, check that the variable is defined in the source code.
You may get C2059 if a symbol evaluates to nothing, as can occur when you compile with /Dsymbol=.
// C2059a.cpp
// compile with: /DTEST=
#include <stdio.h>
int main() {
#ifdef TEST
printf_s("\nTEST defined %d", TEST); // C2059
#else
printf_s("\nTEST not defined");
#endif
}
Another specific reason you can get C2059 is when you compile an
application that specifies a structure in the default arguments for a
function. The default value for an argument must be an expression. An
initializer list, such as that used to initialize a structure, is not an
expression. The resolution is to define a constructor to perform the
required initialization.
The following example generates C2059:
// C2059b.cpp
// compile with: /c
struct ag_type {
int a;
float b;
// Uncomment the following line to resolve.
// ag_type(int aa, float bb) : a(aa), b(bb) {}
};
void func(ag_type arg = {5, 7.0}); // C2059
void func(ag_type arg = ag_type(5, 7.0)); // OK
You can also get C2059 if you define a member template class or
function outside the class. See Knowledge Base article Q241949 for more
information.
C2059 can occur for an ill-formed cast.
The following sample generates C2059:
// C2059c.cpp
// compile with: /clr
using namespace System;
ref class From {};
ref class To : public From {};
int main() {
From^ refbase = gcnew To();
To^ refTo = safe_cast<To^>(From^); // C2059
To^ refTo2 = safe_cast<To^>(refbase); // OK
}
C2059 can also occur if you attempt to create a namespace name that contains a period.
The following sample generates C2059:
// C2059d.cpp
// compile with: /c
namespace A.B {} // C2059
// OK
namespace A {
namespace B {}
}
C2059 can also occur if you define a member template class or function outside the class.
全部回答
- 1楼网友:孤伤未赏
- 2020-07-10 02:09
請追問
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯