非标准语法;请使用 “&” 来创建指向成员的指针,如何解决?

在main.cpp中有问题

Game.cpp......#include "Game.h"
#include<iostream>
#include<string>
#include<time.h>
#include<stdlib.h>
#include<new>
#include<typeinfo>
#include<algorithm>
Game::Game()
{cout << "begin to no paraments initialize......\n";
}Game::Game(const string &n,const string &u,const string &g,const int &m)
{cout << "begin to initialize......\n";this->name = n;this->user = u;this->gun.push_back(g);this->money = m;
}Game::~Game()
{cout << "begin to deconstruct......\n";
}void Game::add_money_base(int in_m)
{cout << "welcome to recharge money!!!\n";this->money += in_m;cout << "your money is: " << this->money << endl;
}void Game::add_gun_base(const string &g)
{cout<<"you has added: "<<g<<" in your gun"<<endl;gun.push_back(g);cout << "your guns are: ";for (vector<string>::iterator i = gun.begin();i != gun.end();i++){cout << *i <<" ";}cout << endl;
}void Game::show_gun_base()
{for (vector<string>::iterator i = gun.begin(); i != gun.end(); i++){cout << "your guns are: \n";cout << *i << endl;}
}string & Game::show_game_name_base()
{return name;
}string & Game::show_user_name_base()
{return user;
}void Game::play_game()
{cout << "you are playing: " << name << endl;
}void Game::custom_func_play1()
{cout << "you are playing games......\n";
}void Game::custom_func_play2()
{cout << "you are playing iQOO7......\n";
}
Game1::Game1()
{cout << "begin to no paraments construct......\n";
}Game1::Game1(const string &n, const string &u, const string &g, const int &m,const string &p, const string &game_name):Game(n, u, g, m)
{this->phone_name = p;this->game_name = game_name;
}Game1::~Game1()
{cout << "begin to deconstruct" << endl;
}void Game1::add_car_son(const string &c)
{car.push_back(c);cout << "you has added car !!!\n"<<"your cars are : ";for_each(car.begin(), car.end(), [](string &s) {cout << s <<" "; });cout << endl;
}void Game1::play_game()
{cout << "you are using : "<<phone_name<<" to play -> " <<game_name << endl;
}void Game1::show_message_son(string *f_show_name(), string *f_show_user(), int *f_show_money(), void *show_gun_base())
{cout << "your name is: " << *f_show_user() << endl;cout << "your game name is: " << *f_show_name() << endl;cout << "your money is: " << *f_show_money() << endl;show_gun_base();
}void Game1::show(void *add_money_base(int in_m), void *add_gun_base(const string &g), void *show_gun_base())
{add_gun_base("12234");add_money_base(999);show_gun_base();
}void Game1::custom_func_play1()
{cout << "you are playing games......\n";
}void Game1::custom_func_play2()
{cout << "you are playing iQOO7......\n";
}
Game.h .......
#pragma once
#ifndef GAME_H_
#define GAME_H_#include<string>
#include<vector>
#include<list>
using namespace std;class Game
{private:string name;string user;int money;vector<string>gun;public:Game();Game(const string &n, const string &u, const string &g, const int &m);~Game();void add_money_base(int in_m);void add_gun_base(const string &g);void show_gun_base();string &show_game_name_base();string &show_user_name_base();virtual void play_game();virtual void custom_func_play1() = 0;virtual void custom_func_play2() = 0;
};class Game1:public Game
{private:list<string> car;string phone_name;string game_name;public:Game1();Game1(const string &n, const string &u, const string &g, const int &m, const string &p,const string &game_name);~Game1();void add_car_son(const string &c) ;virtual void play_game();void show_message_son(string *f_show_name(), string *f_show_user(),int *f_show_money(), void *show_gun_base());void show(void *add_money_base(int in_m),void *add_gun_base(const string &g),void *show_gun_base());virtual void custom_func_play1();virtual void custom_func_play2();};
#endif
main.cpp  .......
#include <iostream>
#include<map>
#include<string>
#include<vector>
#include<time.h>
#include<stdlib.h>
#include<new>
#include<typeinfo>
#include "Game.h"using namespace std;int main()
{Game1 hpjy;hpjy.add_gun_base("98k");hpjy.add_money_base(10);hpjy.add_gun_base("AWM");hpjy.add_money_base(10);hpjy.add_gun_base("M416");hpjy.add_money_base(10);cout << endl;/*Game peace_elite("zjl", "peace elite", "AWM", 0);peace_elite.show_gun_base();cout << "your game name is: " << peace_elite.show_game_name_base() << endl;cout << "your name is: " << peace_elite.show_user_name_base() << endl;peace_elite.add_money_base(666);cout << endl;*/Game1 kybc;kybc.add_car_son("BMW");kybc.add_money_base(10);kybc.add_car_son("audi");kybc.add_money_base(10);kybc.add_car_son("iQOO");kybc.add_money_base(10);Game *g = new Game1("peace_elite", "xwa", "M416", 777, "iQOO", "peace_elite");g->play_game();cout << g->show_game_name_base() << endl;Game1 iQOO("peace_elite", "xwa", "M416", 777, "iQOO", "peace_elite");iQOO.custom_func_play1();iQOO.custom_func_play2();//下面两处有问题:非标准语法;请使用 "&" 来创建指向成员的指针,如何解决?//iQOO.show_message_son(&Game::show_user_name_base,iQOO.show_game_name_base,iQOO.add_money_base,iQOO.show_gun_base);//iQOO.show(&Game::add_money_base, iQOO.add_gun_base, iQOO.show_gun_base);return 0;
}

c++类对象的例子(非标准语法;请使用 ““ 来创建指向成员的指针,如何解决?)相关推荐

  1. c/c++ 报错:非标准语法,使用&创建指向成员的指针的解决办法

    发生这种错误一般是因为使用了一些函数,而没有加括号导致的,这些函数一般没有参数,所以没有意识到错误. 例: string s; s.c_str; //报错 应该为 s.c_str();

  2. error C3867:非标准语法;请使用“”来创建指向成员的指针

    C++实战宝典 上一篇链接: C++使用vector容器遍历时迭代器失效问题 文章目录 一.问题描述 二.原因分析 三.解决方案 四.总结 新壁纸 一.问题描述 类成员函数作为函数参数出现error ...

  3. error C3867: “XXX::XXX”: 非标准语法;请使用 ““ 来创建指向成员的指针。

    VS初学C++模板,想用C++写个栈,结果出现error C3867: "XXX::XXX": 非标准语法:请使用 "&" 来创建指向成员的指针. 因为 ...

  4. 非标准语法;请使用 _一文读懂使用MCU SPI访问具有非标准SPI接口ADC的方法

    好文章当然要分享啦~如果您喜欢这篇文章,请联系后台添加白名单,欢迎转载哟~ 问题 能否用MCU访问非标准SPI接口? 答案 可以,但可能需要做一些额外的努力. 当前许多精密模数转换器(ADC)具有串行 ...

  5. 非标准语法;请使用 _国际汉语教学中 语法点讲解的具体方法

    汉语老师要想将语法点教活,让学生学得轻松,掌握得牢固,不仅要清楚讲解一个语法点(项目)时应该教些什么,更要熟练掌握各种实用和适用的语法点讲解方法.前面的文章和大家分享了给学习汉语的外国朋友讲解一个语法 ...

  6. python对象编程例子-Python 面向对象编程实例讲解

    如果你没有任何以往的经验与面向对象(OO)编程,你可能想咨询或至少某种教程的入门课程,所以,你必须掌握的基本概念. 然而,这里是小推出的面向对象编程(OOP)给你带来更好的学习速度: OOP的术语概述 ...

  7. C++类对象在内存中的布局

    目录 一.前言 二.C++ 类对象的内存布局 2.1 只有数据成员的对象 2.2 没有虚函数的对象 2.3 拥有仅一个虚函数的类对象 2.4 拥有多个虚函数的类对象 三.继承关系中的C++类对象内存分 ...

  8. python类的定义和创建_Python类对象的创建和使用

    通过前面章节的学习,我们已经学会如何定义一个类,但要想使用它,必须创建该类的对象. 创建类对象的过程,又称为类的实例化. 类名(参数) 定义类时,如果没有手动添加 __init__() 构造方法,又或 ...

  9. 【C++学习】对私有构造析构函数的思考:new一个类对象vs直接创建类对象

    前置知识: new的类对象需要手动delete.且使用堆空间.且只能用指针接收. 直接创建的类对象创建在栈中(或说堆栈).不需要手动delete,随着生存周期的结束(如所在的函数return了)而释放 ...

最新文章

  1. 7.12 其他面向对象设计原则3: 依赖倒置原则DIP
  2. 动态调用Web Service
  3. 我们和计算机系的老教授聊了聊TCP优化与产学矛盾
  4. 从汇编来看i++与++i
  5. 游戏筑基开发之结构体定义动态数组及常见问题(C语言)
  6. 从程序员到项目经理(17):你不是一个人在战斗--思维一换天地宽【转载】
  7. 【模板】堆优化 + dij +pair 存储
  8. 电信版行货黑莓9630修复历险记
  9. 成功架构设计的关键要素
  10. Apache Shiro 全面源码解析汇总
  11. 微信公众号开发-账号类型
  12. 物联网常见概念总结(期末复习)
  13. JS阻止form表单提交失败
  14. 【Python金融量化】零基础如何开始学?
  15. 程序员如何修炼项目管理能力?
  16. 【C语言】练习函数调用
  17. 锁系列:一、悲观 / 乐观锁原理与运用
  18. 计算长方形的周长和面积
  19. 安卓手机如何下载ZOOM?
  20. 【selenium自动化】04 xpath高级语法css高级语法

热门文章

  1. Docker入门之路(一):部署Nginx
  2. 第二十六篇:USB3.0高带宽ISO(48KBytes/125us)实战
  3. 带你10分钟学会 Git Extensions
  4. 摄氏温度转换华氏温度
  5. Anylogic各个版本的功能对比
  6. MAC版画图软件 paintbrush 推荐,类似 windows 上系统自带的画图软件
  7. 第七章 区块链政策与法规 [32]
  8. JS 计算时间差【单位:分钟】
  9. scala和java类_Scala(和Java)中的类和类型有什么区别?
  10. 计算机为什么找不到摄像头,win7系统摄像头图标不见怎么办?找回win7摄像头图标的两种方法...