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

请问程序错在哪里?

[复制链接]
发表于 2009-11-2 02:38:59 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include<string>
using namespace System;
using namespace std;
struct Entry {
string name;
int number;
};

template<class T> class Vec : public vector<T> {
public:
Vec() : vector<T>() {}
Vec(int s): vector<T>(s){}
T & operator [ ]( int i ) { return at[i]; }
const T& operator[ ]( int i ) const { return at[i]; }
};
Vec<Entry> phone_book(1000);
int _tmain()
{
// TODO: Please replace the sample code below with your own.
Console::WriteLine(S"Hello World");
return 0;
}


----------我什么有下面的编译错误?请多多指教:)
error C2109: subscript requires array or pointer type
test1.cpp(26) : while compiling class-template member function 'Entry &Vec<T>::operator [](int)'
with
[
T=Entry
]
test1.cpp(30) : see reference to class template instantiation 'Vec<T>' being compiled
with
[
T=Entry
]
发表于 2009-11-2 02:39:00 | 显示全部楼层 IP:江苏扬州

  1. return at[i];
复制代码


at是什么? 是vector里的?, 另外 Vec 类没实现新功能,有必要?
回复

使用道具 举报

发表于 2009-11-2 02:39:03 | 显示全部楼层 IP:江苏扬州
  1. 你给的这段程序不完整啊,namespace System是哪里的………………
  2. 我改了下,没编译错误:
  3. #include <vector>
  4. #include <string>
  5. //using namespace System; 哪里的?
  6. using namespace std;
  7. struct Entry {
  8. string name;
  9. int number;
  10. };
  11. template<class T> class Vec : public vector<T> {
  12. public:
  13. Vec() : vector<T>() {}
  14. Vec(int s): vector<T>(s){}
  15. T & operator [ ]( int i ) { return at[i]; }
  16. const T& operator[ ]( int i ) const { return at[i]; }
  17. };
  18. Vec<Entry> phone_book(1000);
  19. int _tmain()
  20. {
  21. // TODO: Please replace the sample code below with your own.
  22. //Console::WriteLine(S"Hello World"); 这是?我不懂
  23. return 0;
  24. }

复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-29 23:29 , Processed in 0.205841 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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