| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 552 人关注过本帖
标题:[求助]新人,刚刚学习有问题想请教
取消只看楼主 加入收藏
ichigo
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2007-5-27
收藏
 问题点数:0 回复次数:2 
[求助]新人,刚刚学习有问题想请教

今天按照书上的程序输入进去可是怎么修改也无法运行,不知道哪里出错了,谁能帮一下,谢谢了

#include <iostream>
using namespace std;

const int DefaultSize = 10;

class Animal
{
public:
Animal(int);
Animal();
~Animal() {}
int GetWeight() const { return itsWeight; }
void Display() const { std::cout << itsWeight; }
private:
int itsWeight;
};

Animal::Animal ( int weight):
itsWeight(weight)
{}

Animal::Animal():
itsWeight(0)
{}

template <class T>
class Array
{
public:
Array(int itsSize = DefaultSize);
Array(const Array &rhs);
~Array() { delete [] pType; }

Array& operator=(const Array&);
T& operator[](int offSet) { return pType[offSet]; }
const T& operator[](int offSet) const
{return pType[offSet]; }
int GetSize() const { return itsSize; }
template <class T>
friend ostream& operator<< (ostream&, Array<T>&);
private:
T *pType;
int itsSize;
};

template <class T>
ostream& operator<< (ostream& output, Array<T>& theArray)
{
for(int i=0; i<theArray.itsSize; i++)
output << "[" << i << "]" << theArray[i] << endl;
return output;
}

template <class T>
Array<T>::Array(int size):
itsSize(size)
{
pType = new T[size];
for (int i=0; i<size; i++)
pType[i] =0;
}

template <class T>
Array<T>::Array(const Array &rhs)
{
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i=0; i<itsSize; i++)
pType[i] = rhs[i];
}

template <class T>
Array<T>& Array<T>::operator=(const Array &rhs)
{
if (this == &rhs)
return *this;
delete [] pType;
itsSize = rhs.GetSize();
pType = new T[itsSize];
for (int i=0; i< itsSize; i++)
pType[i] = rhs[i];
return * this;
}

int main()
{
bool Stop = false;
int offset, value;
Array<int> theArray;
while (Stop == false)
{
cout << "Enter an offset (0-9) ";
cout << "and a value. (-1 to stop): ";
cin >> offset >> value;

if (offset<0)
break;
if (offset>9)
{
cout << "***Please use values between 0 and 9.***\n";
continue;
}

theArray[offset] = value;
}

cout << "\nHere's the entire array:\n";
cout << theArray << endl;
char response;
cin >> response;
return 0;
}


在108行处
就是cout << theArray << endl;这里编译器提示错误是
D:\C++\第三周\19.3.cpp(108) : error C2563: mismatch in formal parameter list
D:\C++\第三周\19.3.cpp(108) : error C2568: '<<' : unable to resolve function overload
could be 'class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &__cdecl std::endl(class std::basic_ostream<unsigned short,struct std::char_traits<unsigned short> > &)'
d:\microsoft visual studio\vc98\include\ostream(377) : see declaration of 'endl'
or 'class std::basic_ostream<char,struct std::char_traits<char> > &__cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)'
d:\microsoft visual studio\vc98\include\ostream(372) : see declaration of 'endl'
or 'class std::basic_ostream<_E,_Tr> &__cdecl std::endl(class std::basic_ostream<_E,_Tr> &)'
d:\microsoft visual studio\vc98\include\ostream(367) : see declaration of 'endl'
执行 cl.exe 时出错.

这个问题解决不了下边的知识都有类似的地方...所以希望大家帮忙解决,非常感谢!!

搜索更多相关主题的帖子: 新人 学习 
2007-05-27 20:02
ichigo
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2007-5-27
收藏
得分:0 
还是不行...别人说用vc8直接能译过去,没有错误,可是vc8我下了一个安装不了。..总是下载完成就出错...
2007-05-29 09:48
ichigo
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2007-5-27
收藏
得分:0 
那能给我发个2005的安装程序吗...我想用那个...
2007-05-29 11:00
快速回复:[求助]新人,刚刚学习有问题想请教
数据加载中...
 
   



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

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