注册 登录
编程论坛 C++教室

怎么会出错呢?

Noll_Nie 发布于 2011-05-15 14:15, 376 次点击
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no accep
table conversion)
这是什么意思啊?
指教下吧
4 回复
#2
linw12252011-05-15 14:53
贴代码才是王道。
#3
lintaoyn2011-05-15 15:03
没有重载合适的operator<<吧
#4
Noll_Nie2011-05-15 16:12
程序代码:
#include <iostream>
using namespace std;

class Cbase  
{
public:
    void printtitle(void)const;
    string gettitle(string tit);
    virtual bool isgood() = 0;
    Cbase();
    virtual ~Cbase();

protected:
    string title;
    int volume_of_sales;
};
头文件
下面是实现文件
#include "base.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Cbase::Cbase():title("NoTitle"),volume_of_sales(0)
{

}

Cbase::~Cbase()
{

}

string Cbase::gettitle(string tit)
{
    title = tit;
}

void Cbase::printtitle(void)const
{
    cout<<title<<endl;
}


编译报错啊???
#5
寒风中的细雨2011-05-15 17:26
#include <iostream>
#include <string>
using namespace std;

class Cbase  
{
public:
    void printtitle(void)const;
    string gettitle(string tit);
    virtual bool isgood() = 0;
    Cbase();
    virtual ~Cbase();

protected:
    string title;
    int volume_of_sales;
};

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Cbase::Cbase():title("NoTitle"),volume_of_sales(0)
{

}

Cbase::~Cbase()
{

}

string Cbase::gettitle(string tit)
{
    return title = tit;
}

void Cbase::printtitle(void)const
{
    cout << title << endl;
}
1