标题:请问程序错在哪里?
只看楼主
yvjingxiang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-3-4
 问题点数:0 回复次数:2 
请问程序错在哪里?

#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
]

搜索更多相关主题的帖子: replace include public number 
2006-03-04 16:26
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
得分:0 
[CODE]

return at[i];

[/CODE]

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


2006-03-04 16:42
DarkHero
Rank: 1
等 级:新手上路
威 望:2
帖 子:191
专家分:0
注 册:2006-1-14
得分:0 

[CODE]你给的这段程序不完整啊,namespace System是哪里的………………
我改了下,没编译错误:
#include <vector>
#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;
}


[/CODE]


for( ; me.alive() ; ) { 淡泊名利,志存高远 } //Forever
2006-03-04 16:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-48423-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.729340 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved