05_0824_编写String的问题(C++)

来源:互联网 发布:javascript权威指南 7 编辑:程序博客网 时间:2024/05/17 00:00

主函数如下:
#include "stdafx.h"
#include "iostream.h"
#include "String.h"
void main()
{
 String str;
 str='a';
★ cout<<str<<endl;

}
String类的定义如下:
class String 
{
public:
 String();
 virtual ~String();
public:
 String& operator=(char chVar);
protected:
 char* m_pszBuffer;
 int m_nLength;
};
String类的实现如下:
#include "stdafx.h"
#include "String.h"
String::String()
{}
String &String::operator = (char chVar)
{
 m_pszBuffer=new char[2];
 m_pszBuffer[0]=chVar;
 m_pszBuffer[1]='/0';
 return *this;
}
String::~String()
{}

程序编译出现如下问题:
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class String' (or there is no acceptable conversion)
Error executing cl.exe.
指向带有★的行。