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 containing the open curly brace, but the true source of the error appears on the line just above it. // C2059a.cpp int main ) // C2059 No opening parenthesis. { } 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=.// C2059b.cpp // compile with: /DTEST= #include <stdio.h> int main() { #ifdef TEST printf("\nTEST defined %d", TEST); // C2059 #else printf("\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 following example generates C2059:// C2059c.cpp struct ag_type { int a; float b; };void func(ag_type arg = {5, 7.0}); // C2059 The resolution is to define a constructor to perform the required initialization. struct ag_type { int a; float b; ag_type(int aa, float bb) : a(aa), b(bb) {} }; void func(ag_type arg = ag_type(5, 7.0)); int main() { } 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.
void main ( // 这里有问题
{}在双击出错信息提示,在源代码的上一行,或者上几行查找是否有语法错误。
int main ) // C2059 No opening parenthesis.
{
}
如果对行的检查没有获得有关可能出现的问题的任何线索,则尝试注释掉在错误信息中列出的行以及可能出现在该行上面的若干行。如果该错误信息在紧跟 typedef 变量的符号上出现,则检查该变量是否已在源代码中定义。如果符号没有计算出任何结果(在使用 /Dsymbol= 编译时可能发生),则可能会获得 C2059。// C2059b.cpp
// compile with: /DTEST=
#include <stdio.h>
int main()
{
#ifdef TEST
printf("\nTEST defined %d", TEST); // C2059
#else
printf("\nTEST not defined");
#endif
}可能收到 C2059 的另一个特定原因是编译在函数的默认参数中指定了结构的应用程序。参数的默认值必须是一个表达式。初始值设定项列表(如用于初始化结构的初始值设定项列表)不是表达式。下面的示例生成 C2059:// C2059c.cpp
struct ag_type
{
int a;
float b;
};void func(ag_type arg = {5, 7.0}); // C2059
其解决方法是定义一个执行所需初始化的构造函数。struct ag_type {
int a;
float b;
ag_type(int aa, float bb) : a(aa), b(bb) {}
};
void func(ag_type arg = ag_type(5, 7.0));
int main()
{
}
如果您在类外定义成员模板类或函数,也可能获得 C2059。
所以原来的.cpp中必定包含了 stdafx.h .而且我刚才也检查过了!错误出现行是在mfc中的文件中:
_Myt& assign(const _E *_S, size_type _N)
{if (_Grow(_N, true))
{_Tr::copy(_Ptr, _S, _N);
还有一个就是
把原来对话框中的CAboutDlg给删除了,因为是在同一个文件中.
之后也把OnSysCommand事件改成这样:
/*
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
*/
CDialog::OnSysCommand(nID, lParam);
int main ) // C2059 No opening parenthesis.
{
}
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=.// C2059b.cpp
// compile with: /DTEST=
#include <stdio.h>
int main()
{
#ifdef TEST
printf("\nTEST defined %d", TEST); // C2059
#else
printf("\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 following example generates C2059:// C2059c.cpp
struct ag_type
{
int a;
float b;
};void func(ag_type arg = {5, 7.0}); // C2059
The resolution is to define a constructor to perform the required initialization. struct ag_type {
int a;
float b;
ag_type(int aa, float bb) : a(aa), b(bb) {}
};
void func(ag_type arg = ag_type(5, 7.0));
int main()
{
}
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.
果然是那个cpp文件啊,
namespace XXX
{ 名字空间中没有加括号。还本这里有一个CAboutDlg,
有个namespace XXX,后来删除的时候没有删干尽。(
我在原本的工程中所有的类
都加上了名字空间。
)