C++ Visual Studio 2015:非标准语法;使用“&”创建指向成员的指针
C++ Visual Studio 2015: non-standard syntax; use '&' to create a pointer to member
Card.h
#pragma once
#include <string>
#include "Rank.h"
#include "Suit.h"
using namespace std;
/**
*
*/
class MEMORYWARS_API Card
{
public:
Card(Rank, Suit);
string toString() const;
~Card();
private:
Rank rank;
Suit suit;
};
Card.cpp
#include "MemoryWars.h"
#include "Card.h"
Card::Card(Rank rank, Suit suit)
{
this->rank = rank;
this->suit = suit;
}
string Card::toString() const
{
string s = "Hellow there";
return s;
}
Card::~Card()
{
}
错误
error C3867: 'Card::toString': non-standard syntax; use '&' to create a pointer to member
Deck.h
#pragma once
#include "Card.h"
#include "vector"
class MEMORYWARS_API Deck
{
public:
Deck();
~Deck();
private:
std::vector<Card> deck;
};
Deck.cpp
#include "MemoryWars.h"
#include "Deck.h"
#include <EngineGlobals.h>
#include <Runtime/Engine/Classes/Engine/Engine.h>
Deck::Deck()
: deck(52)
{
int cc = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 13; j++)
{
Rank rank = static_cast<Rank>(j);
Suit suit = static_cast<Suit>(i);
deck[cc] = Card(rank, suit);
cc++;
}
}
string st = deck[2].toString;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Some variable values: x: %s"), st));
}
Deck::~Deck()
{
}
我是 C++ 的新手,主要有 Java 经验,我一直在为这个错误而苦苦挣扎。
我正在尝试测试 Card::toString 方法,但每次从 deck.cpp 调用它时我都会收到错误消息。
这里这行不正确:
string st = deck[2].toString;
在 C++ 中调用函数的正确方法(实际上 Java 我也这么认为)是这样的:
string st = deck[2].toString();
Card.h
#pragma once
#include <string>
#include "Rank.h"
#include "Suit.h"
using namespace std;
/**
*
*/
class MEMORYWARS_API Card
{
public:
Card(Rank, Suit);
string toString() const;
~Card();
private:
Rank rank;
Suit suit;
};
Card.cpp
#include "MemoryWars.h"
#include "Card.h"
Card::Card(Rank rank, Suit suit)
{
this->rank = rank;
this->suit = suit;
}
string Card::toString() const
{
string s = "Hellow there";
return s;
}
Card::~Card()
{
}
错误
error C3867: 'Card::toString': non-standard syntax; use '&' to create a pointer to member
Deck.h
#pragma once
#include "Card.h"
#include "vector"
class MEMORYWARS_API Deck
{
public:
Deck();
~Deck();
private:
std::vector<Card> deck;
};
Deck.cpp
#include "MemoryWars.h"
#include "Deck.h"
#include <EngineGlobals.h>
#include <Runtime/Engine/Classes/Engine/Engine.h>
Deck::Deck()
: deck(52)
{
int cc = 0;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 13; j++)
{
Rank rank = static_cast<Rank>(j);
Suit suit = static_cast<Suit>(i);
deck[cc] = Card(rank, suit);
cc++;
}
}
string st = deck[2].toString;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Some variable values: x: %s"), st));
}
Deck::~Deck()
{
}
我是 C++ 的新手,主要有 Java 经验,我一直在为这个错误而苦苦挣扎。
我正在尝试测试 Card::toString 方法,但每次从 deck.cpp 调用它时我都会收到错误消息。
这里这行不正确:
string st = deck[2].toString;
在 C++ 中调用函数的正确方法(实际上 Java 我也这么认为)是这样的:
string st = deck[2].toString();