第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Visual Studio 2015“非標(biāo)準(zhǔn)語法;使用“&”創(chuàng)建指向成員的指針”

Visual Studio 2015“非標(biāo)準(zhǔn)語法;使用“&”創(chuàng)建指向成員的指針”

C++
慕田峪9158850 2019-11-04 10:59:48
我正在學(xué)習(xí)C ++,并嘗試制作一個Tic Tac Toe的小游戲。但是我繼續(xù)得到非標(biāo)準(zhǔn)語法C3867。使用“&”創(chuàng)建要記住的指針。這是我的TicTacToe.h:#pragma once#include <iostream>using namespace std;class TicTacToe{public:    TicTacToe();    string getName1();    string getName2();    void printBoard();    void clearBoard();    void setName1(string player1Name);    void setName2(string player2Name);    void setSign1(string player1Sign);    void setSign2(string player2Sign, string player1Sign);    void playGame(string player1Name, string player2Name,string    player1Sign,string player2Sign);                      void player1Move(string coordX);    void player1Turn();    void player2Turn();private:    char Board[3][3];    string _player1Name;    string _player2Name;    string _player1Sign;    string _player2Sign;    string _coordX;    string _coordY;};這是我的TicTacToe.cpp:#include "TicTacToe.h"#include <iostream>#include <string>TicTacToe::TicTacToe() {}void TicTacToe::playGame(string player1Name, string player2Name,                         string player1Sign, string player2Sign) {  TicTacToe Board;  Board.setName1(player1Name);  Board.setSign1(player1Sign);  Board.setName2(player2Name);  Board.setSign2(player1Sign, player2Sign);  Board.clearBoard();  Board.printBoard();}void TicTacToe::printBoard() {  cout << " |1|2|3|\n";  for (int i = 0; i < 3; i++) {    cout << "--------\n";    cout << i + 1 << "|" << Board[i][0] << "|" << Board[i][1] << "|"         << Board[i][2] << "|" << endl;  }}void TicTacToe::clearBoard() {  for (int i = 0; i < 3; i++) {    for (int j = 0; j < 3; j++) {      Board[i][j] = ' ';    }  }}void TicTacToe::setName1(string player1Name) {  cout << "Enter your name, player 1: \n";  cin >> player1Name;  _player1Name = player1Name;}void TicTacToe::setName2(string player2Name) {  cout << "Enter your name, player 2: \n";  cin >> player2Name;  _player2Name = player2Name;}string TicTacToe::getName1() { return _player1Name; }string TicTacToe::getName2() { return _player2Name; }我已經(jīng)嘗試了其他所有有關(guān)此錯誤的問題,但它們沒有起作用。您如何解決此錯誤?
查看完整描述

3 回答

?
皈依舞

TA貢獻1851條經(jīng)驗 獲得超3個贊

問題在于包含以下內(nèi)容的行(它在您的代碼中出現(xiàn)兩次):


Board.player1Move;

播放器的一招是一個函數(shù),該函數(shù)接收std :: string參數(shù)作為輸入。為了調(diào)用它,您需要創(chuàng)建一個std :: string對象并將其作為函數(shù)的參數(shù)傳遞。如果希望將字符串作為輸入給出,則可以使用以下語法:


std::string move;

cin >> move;

Board.player1Move(move);

另外,請注意,player2Turn應(yīng)該調(diào)用Board.player2Move而不是Board.player1Move。


查看完整回答
反對 回復(fù) 2019-11-04
?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

drorco的答案中已經(jīng)提供了解決問題的方法。我將嘗試解釋錯誤消息。


當(dāng)您具有非成員函數(shù)時,可以在表達式中使用函數(shù)名稱,而無需使用函數(shù)調(diào)用語法。


void foo()

{

}


foo; // Evaluates to a function pointer.

但是,當(dāng)您具有成員函數(shù)時,在沒有函數(shù)調(diào)用語法的表達式中使用成員函數(shù)名稱無效。


struct Bar

{

   void baz() {}

};


Bar::baz;  // Not valid.

要獲得指向成員函數(shù)的指針,您需要使用&運算符。


&Bar::baz;   // Valid

這解釋了Visual Studio的錯誤消息:


"non-standard syntax; use '&' to create a pointer to member"


查看完整回答
反對 回復(fù) 2019-11-04
  • 3 回答
  • 0 關(guān)注
  • 858 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號