碰到一个奇怪的编绎错误 C2059

Meuck 2004-04-30 05:01:49
d:\program files\microsoft visual studio\vc98\include\xstring(133) : error C2059: syntax error : 'end of file'

当我把另一个工程的文件拷贝的这个工程中,解决了所有头文件的错误之后.
出现的.(有Dialog)
...全文
54 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
Meuck 2004-04-30
  • 打赏
  • 举报
回复
这个错误一下子就跳到MFC中,把我给搞糊涂了,呵呵。
Meuck 2004-04-30
  • 打赏
  • 举报
回复
问题找到了!,谢谢 。
果然是那个cpp文件啊,
namespace XXX
{

名字空间中没有加括号。还本这里有一个CAboutDlg,
有个namespace XXX,后来删除的时候没有删干尽。

(
我在原本的工程中所有的类
都加上了名字空间。
)
暗黑帝国 2004-04-30
  • 打赏
  • 举报
回复
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.
Meuck 2004-04-30
  • 打赏
  • 举报
回复
不知道为什么,其它文件都没事,就只有Dialog的那个有问题.
Kudeet 2004-04-30
  • 打赏
  • 举报
回复
语法错误
在出错附近几行找一下
Meuck 2004-04-30
  • 打赏
  • 举报
回复
而我之后改的也是如 resource.h 和一些头文件的路径,
还有一个就是
把原来对话框中的CAboutDlg给删除了,因为是在同一个文件中.
之后也把OnSysCommand事件改成这样:
/*
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
*/
CDialog::OnSysCommand(nID, lParam);
Meuck 2004-04-30
  • 打赏
  • 举报
回复
我是从另外一个工程中拷进来的文件,在原来的工程中是可以运行的.
所以原来的.cpp中必定包含了 stdafx.h .而且我刚才也检查过了!

错误出现行是在mfc中的文件中:
_Myt& assign(const _E *_S, size_type _N)
{if (_Grow(_N, true))
{_Tr::copy(_Ptr, _S, _N);
wwwsq 2004-04-30
  • 打赏
  • 举报
回复
'end of file'是什么dd?
doubhua 2004-04-30
  • 打赏
  • 举报
回复
我遇到过几次这样的问题,提示文件未完什么的。双击出错信息提示,它把我带到这个文件的最后一行,怎么检查也没有错。最后发现原因就是没有加入stdafx.h,所有使用了预编译头的工程中,每个文件都必须加入stdafx.h。
wwwsq 2004-04-30
  • 打赏
  • 举报
回复
stdafx.h 通常应该第一个包含,请检查你的头文件包含的顺序。

如果顺序没问题,请检查你的宏定义。
LuWei103 2004-04-30
  • 打赏
  • 举报
回复
该标记导致语法错误。

若要确定原因,则不仅要检查在错误信息中列出的行,还要检查该行上面的行。以下示例对包含左大括号的行生成了错误信息,而该错误的真正原因却出现在其上面的行中。

// C2059a.cpp
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。
summit1208 2004-04-30
  • 打赏
  • 举报
回复
#include "stdafx.h"
王国凡 2004-04-30
  • 打赏
  • 举报
回复
是语法错误,例如:
void main ( // 这里有问题
{

}

在双击出错信息提示,在源代码的上一行,或者上几行查找是否有语法错误。
Meuck 2004-04-30
  • 打赏
  • 举报
回复
所有.cpp都加了头文件啊.
wwwsq 2004-04-30
  • 打赏
  • 举报
回复
在这个cpp文件的头上包含 stdafx.h 试试
Meuck 2004-04-30
  • 打赏
  • 举报
回复
please help me

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧