***菜鸟求助,函数内的函数???

LuckyJan 2010-08-09 09:52:30

===== c1.cpp =====
#include "c1.h"
namespace testDLL
{
void testFunc1()
{
......
}
}

===== c2.cpp =====
#include "c2.h"
namespace testDLL
{
void testFunc2()
{
void testFunc1(); // ???? error LNK2019: 无法解析的外部符号 "void __cdecl testFunc1(void)" ....
testFunc1(); // ????
}
}

=============================编译时不通过==========================
XXX.obj : error LNK2019: 无法解析的外部符号 "void __cdecl testFunc1(void)" (?testFunc1@@YAXXZ),
该符号在函数 "public: void __thiscall testDLL::Class2::DestructInterfaces(void)" (?DestructInterfaces@Class2@testDLL@@QAEXXZ) 中被引用
...全文
87 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanchenyu 2010-08-11
  • 打赏
  • 举报
回复
三楼正解
yaoyuan2 2010-08-09
  • 打赏
  • 举报
回复
===== c2.cpp =====
#include "c2.h"
#include "c1.h" //!!! 加上此行

namespace testDLL
{
void testFunc2()
{
void testFunc1(); // ???? error LNK2019: 无法解析的外部符号 "void __cdecl testFunc1(void)" ....
testFunc1(); // ????
}
}

此方式适合:testFunc1()只供testFunc2()调用
一般不用此声明方式
abcmacai 2010-08-09
  • 打赏
  • 举报
回复
您是想在函数内调用函数吧, 直接testFunc1(); 就Ok了
声明一点,貌似没见过在函数内声明函数的
LuckyJan 2010-08-09
  • 打赏
  • 举报
回复
版主:为什么在函数testFunc2()内声明函数testFunc1()????
wangkunyue 2010-08-09
  • 打赏
  • 举报
回复
太好啦!
  • 打赏
  • 举报
回复
名字空间作用域问题

VC认为函数内部声明的函数在全局作用域下面。

所以你得在testDLL名字空间下声明函数
namespace testDLL
{
void testFunc1();
void testFunc2()
{

testFunc1();
}
}

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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