程序员女妹子求助!
关于友元函数的一个程序,编译不成功,不知道哪儿的问题#include<iostream>
using namespace std ;
class Data ;//对Date类的声明
class Time
{
public:
Time(int , int , int) ;
friend void display(const Date & , const Time &);//将普通函数display声明为朋友
private:
int hour ;
int minute ;
int sec ;
};
Time::Time(int h , int m , int s)
{
hour = h ;
minute = m ;
sec = s ;
}
class Date
{
public:
Date (int , int , int);
friend void display(const Date & , const Time &);//将普通函数display声明为朋友
private:
int month ;
int day ;
int year ;
};
Date::Date(int m , int d , int y )
{
month = m ;
day = d ;
year = y ;
}
void dispaly(const Date &d , const Time &t)
{
cout << d.month << "/" << d.day << "/" << d.year << endl ;
cout << t.hour << ":" << t.minute << ":" << t.sec << endl ;
}
int main()
{
Date t1(12 , 25 , 2014) ;
Time t2 (10 , 13 , 56);
display(t1 , t2);
return 0 ;
}
#include<iostream>
using namespace std;
//class Data ;//对Date类的声明
class Date ;//对Date类的声明
class Time
{
public:
Time(int h , int m , int s);
friend void display(const Date &, const Time &);//将普通函数display声明为朋友
private:
int hour ;
int minute ;
int sec ;
};
Time::Time(int h , int m , int s)
{
hour = h ;
minute = m ;
sec = s ;
}
class Date
{
public:
Date (int , int , int);
friend void display(const Date &, const Time &);//将普通函数display声明为朋友
private:
int month ;
int day ;
int year ;
};
Date::Date(int m , int d , int y )
{
month = m ;
day = d ;
year = y ;
}
//void dispaly(const Date &d, const Time &t)
void display(const Date &d, const Time &t)
{
cout << d.month << "/" << d.day << "/" << d.year << endl ;
cout << t.hour << ":" << t.minute << ":" << t.sec << endl ;
}
int main()
{
Date t1(12 , 25 , 2014) ;
Time t2 (10 , 13 , 56);
display(t1 , t2);
return 0 ;
}
楼主该打!这单词。。。 虽然我看不懂但是你可以从反编译那边寻找答案 #include <iostream>
#include <string>
#include <stdlib.h>
class Lovers //创建基类和子类
{
public:
Lovers(std::string theName); //基类构造器
void kiss(Lovers *lover);
void ask(Lovers *lover, std::string something);
protected:
std::string name;
friend class Others;
};
class Boyfriend : public Lovers //创建子类并继承基类
{
public:
Boyfriend(std::string theName); //子类构造器
};
class Girlfriend : public Lovers
{
public:
Girlfriend(std::string tneName);
};
class Others
{
public:
Others(std::string theName);
void kiss(Lovers *lover);
protected:
std::string name;
};
/**************************************/
Lovers::Lovers(std::string theName) //基类构造器和方法的定义
{
name = theName;
}
void Lovers::kiss(Lovers *lover) //对基类函数的定义
{
std::cout << name << "亲亲我的宝贝" << lover ->name << std::endl;
}
void Lovers::ask(Lovers *lover, std::string something) //基类函数
{
std::cout << "宝贝" << lover->name << "和我" << something << std::endl;
}
Boyfriend::Boyfriend(std::string theName) : Lovers(theName) //对子类构造器的定义继承
{
}
Girlfriend::Girlfriend(std::string theName) : Lovers(theName) //子类构造器
{
}
Others::Others(std::string theName)
{
name = theName;
}
void Others::kiss(Lovers *lover)
{
std::cout << name << "亲一下" << lover->name << std::endl;
}
/********************************************/
int main()
{
Boyfriend boyfriend("小妞");
Girlfriend girlfriend("靓妹");
Others others("帅哥");
girlfriend.kiss(&boyfriend);
girlfriend.ask(&boyfriend, "上床睡觉啦");
std::cout << "\n当当当当!传说中的帅哥登场........\n";
others.kiss(&girlfriend);
return 0;
system("pause");
} .·_Alone 发表于 2014-5-3 15:53 static/image/common/back.gif
虽然我看不懂但是你可以从反编译那边寻找答案
反编译是个什么东东 HHR 发表于 2014-5-3 16:04 static/image/common/back.gif
楼主该打!这单词。。。
你精神上已经打击到我了。。 青玄 发表于 2014-5-3 17:39 static/image/common/back.gif
亲爱的,你很有才哦,不过貌似不是我的答案耶 qq小小七 发表于 2014-5-4 13:45 static/image/common/back.gif
亲爱的,你很有才哦,不过貌似不是我的答案耶
额!过奖,过奖!我只是把小甲鱼的代码贴出来而已,想让你借鉴的看一下,呵呵!其实,我和你一样,很菜的!
页:
[1]