找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 518|回复: 8

error LNK2001: unresolved external symbol??

[复制链接]
发表于 2009-11-6 01:11:10 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include <iostream>
using namespace std;
class Juzhen
{
public:
static void set1();
//void set1();
void set2();
void display();
private:
static int x;
static int y;
//int x;
//int y;
int*p;
};
void Juzhen::set1()
{
cout<<"输入行数和列数"<<endl;
cin>>x>>y;
}
void Juzhen::set2()
{
int a=(x-1)*(y-1);
p=new int [a];
cout<<"输入一个"<<x<<"行"<<y<<"列的矩阵"<<endl;
for(int i=0,b=0;i<x;i++)
for(int j=0;j<y;j++,b++)
cin>>p[b];
cout<<endl;
}
void Juzhen::display()
{
for(int i=0,b=0;i<x;i++){
for(int j=0;j<y;j++,b++)
cout<<p[b]<<" ";
cout<<endl;}
}
int main()
{
Juzhen j1;
Juzhen::set1();
//j1.set1();
j1.set2();
j1.display();
return 0;
}
错误报告:
--------------------Configuration: 的 - Win32 Debug--------------------
Linking...
lizi.obj : error LNK2001: unresolved external symbol "private: static int Juzhen::x" (?x@Juzhen@@0HA)
lizi.obj : error LNK2001: unresolved external symbol "private: static int Juzhen::y" (?y@Juzhen@@0HA)
Debug/的.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.
的.exe - 1 error(s), 0 warning(s)


请问这是什么错误啊?怎样才能解决啊?谢谢~~
发表于 2009-11-6 01:11:12 | 显示全部楼层 IP:江苏扬州
静态变量初始化呢?
回复

使用道具 举报

发表于 2009-11-6 01:11:13 | 显示全部楼层 IP:江苏扬州
静态变量初始化后出现的错误:
--------------------Configuration: 的 - Win32 Debug--------------------
Compiling...
lizi.cpp
Linking...
qdds.obj : error LNK2005: "public: static void __cdecl Juzhen::set1(void)" (?set1@Juzhen@@SAXXZ) already defined in lizi.obj
qdds.obj : error LNK2005: "public: void __thiscall Juzhen::set2(void)" (?set2@Juzhen@@QAEXXZ) already defined in lizi.obj
qdds.obj : error LNK2005: "public: void __thiscall Juzhen::display(void)" (?display@Juzhen@@QAEXXZ) already defined in lizi.obj
qdds.obj : error LNK2005: _main already defined in lizi.obj
Debug/的.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
的.exe - 1 error(s), 0 warning(s)
回复

使用道具 举报

发表于 2009-11-6 01:11:14 | 显示全部楼层 IP:江苏扬州
肯定是初始化错了!


int Juzhen:: x = 1;
int Juzhen:: y = 1;
这样哦!!!
回复

使用道具 举报

发表于 2009-11-6 01:11:16 | 显示全部楼层 IP:江苏扬州
按你说的初始化了,错误报告还是没任何改变!
回复

使用道具 举报

发表于 2009-11-6 01:11:17 | 显示全部楼层 IP:江苏扬州
在网上找到个类似的错误,可惜没有给出解决的方案,那里的说法是Juzhen类的成员函数重定义了,造成无法链接。
回复

使用道具 举报

发表于 2009-11-6 01:11:19 | 显示全部楼层 IP:江苏扬州
问题是你初始化的位置,我看我发上来算了,呵呵!
  1. #include <iostream>
  2. using namespace std;
  3. class Juzhen
  4. {
  5. public:
  6. static void set1();
  7. //void set1();
  8. void set2();
  9. void display();
  10. private:
  11. static int x;
  12. static int y;
  13. //int x;
  14. //int y;
  15. int*p;
  16. };
  17. int Juzhen:: x = 1;
  18. int Juzhen:: y = 1;
  19. void Juzhen::set1()
  20. {
  21. cout<<"输入行数和列数"<<endl;
  22. cin>>x>>y;
  23. }
  24. void Juzhen::set2()
  25. {
  26. int a=(x-1)*(y-1);
  27. p=new int [a];
  28. cout<<"输入一个"<<x<<"行"<<y<<"列的矩阵"<<endl;
  29. for(int i=0,b=0;i<x;i++)
  30. for(int j=0;j<y;j++,b++)
  31. cin>>p[b];
  32. cout<<endl;
  33. }
  34. void Juzhen::display()
  35. {
  36. for(int i=0,b=0;i<x;i++){
  37. for(int j=0;j<y;j++,b++)
  38. cout<<p[b]<<" ";
  39. cout<<endl;}
  40. }
  41. int main()
  42. {
  43. Juzhen j1;
  44. Juzhen::set1();
  45. //j1.set1();
  46. j1.set2();
  47. j1.display();
  48. return 0;
  49. }
复制代码

再有问题,就无语了!我能通过的!
回复

使用道具 举报

发表于 2009-11-6 01:11:20 | 显示全部楼层 IP:江苏扬州
静态成员变量要在类外部定义一下,倒不一定要初始化。
在类里面只能算声明。
回复

使用道具 举报

发表于 2009-11-6 01:11:21 | 显示全部楼层 IP:江苏扬州
对于静态成员,在主函数使用之前必须初始化
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 15:31 , Processed in 0.187049 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表