鱼C论坛

 找回密码
 立即注册
查看: 5456|回复: 0

在友元关系一节中,在main函数中调用出错。帮忙看看~

[复制链接]
发表于 2013-8-31 13:46:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<iostream>

  2. class Lovers//lovers基类
  3. {
  4. public:
  5. Lovers(std::string theName)
  6. {
  7. name = theName;//对参数name进行初始化
  8. }
  9. void kiss(Lovers * lover)
  10. {
  11. std::cout<<&name<<"我们家的"<<&lover->name<<std::endl;
  12. }
  13. ;
  14. void ask(Lovers * lover,std::string something)
  15. {
  16. std::cout<<&lover->name<<"帮我"<<&something<<std::endl;
  17. }
  18. protected:
  19. std::string name;//可以在子类中访问,但是不能在main中调用

  20. friend class Others;
  21. };

  22. class Boyfriend:public Lovers//lovers子类Boyfriend
  23. {
  24. public:
  25. Boyfriend(std::string theName);
  26. };

  27. class Girlfriend:public Lovers//lovers子类Girlfriend
  28. {
  29. public:
  30. Girlfriend(std::string theName);
  31. };

  32. class Others//others基类
  33. {
  34. public:
  35. Others(std::string theName)
  36. {
  37. name = theName;
  38. }
  39. void kiss(Lovers * lover)
  40. {
  41. std::cout<<&name<<"kiss"<<&lover->name<<std::endl;
  42. }
  43. protected:
  44. std::string name;
  45. };

  46. int main()
  47. {
  48. Boyfriend boy("A哥");
  49. Girlfriend girl("B妹");

  50. Others other("路人");

  51. girl.kiss(&boy);
  52. girl.ask(&boy,"洗衣服");

  53. std::cout<<"\n万恶的路人\n"<<std::endl;

  54. other.kiss(&girl);

  55. return 0;
  56. }
复制代码

error LNK2019: 无法解析的外部符号 "public: __thiscall Boyfriend::Boyfriend(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Boyfriend@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z),该符号在函数 _main 中被引用
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-5 23:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表