非标准语法;请使用 “&” 来创建指向成员的指针,如何解决?
在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;
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();
return 0;
}