zjx2567 发表于 2015-4-26 21:52:32

<<,非法,左操作数包含const char

:cry:cry:cry

小咒 发表于 2015-4-26 22:24:58

请把代码全部帖上来

zjx2567 发表于 2015-4-27 11:07:05

小咒 发表于 2015-4-26 22:24
请把代码全部帖上来

#include "stdafx.h"
#include <iostream>
using namespace std;
class Time;
class Date
{
public:
        Date(int,int,int);
        friend Time;
private:
        int month;
        int day;
        int year;
};
Date::Date(int m,int d,int y):month(m),day(d),year(y){}


class Time
{
public:
        Time(int,int,int);
        void display(const Date &);
private:
        int hour;
        int minute;
        int sec;
};

Time::Time(int h,int m,int s):hour(h),minute(m),sec(s){}

void Time::display(const Date &d)
{
        cout<<d.month<<d.day<<d.year<<endl;
        cout<<hour<<minute<<sec<<endl;
}

int main()
{
        Time t1(10,13,56);
        Date d1(12,25,2004);
        t1.display(d1);
        return 0;
}

小咒 发表于 2015-4-27 11:16:19

//#include "stdafx.h"
把这行注释掉后我运行是正常的,我没有找到有const的左值

zjx2567 发表于 2015-4-28 12:21:52

小咒 发表于 2015-4-27 11:16
//#include "stdafx.h"
把这行注释掉后我运行是正常的,我没有找到有const的左值

我是用VS2012的 你用那种编译器

小咒 发表于 2015-4-28 13:24:34

zjx2567 发表于 2015-4-28 12:21
我是用VS2012的 你用那种编译器

VS2013,我估计你也是工程建错了stdafx.h是MFC头文件。
建立win32控制台
页: [1]
查看完整版本: <<,非法,左操作数包含const char