Lopic
Lopic

Reputation: 67

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

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()
{
}

I'm new to C++ with Java experience mainly, I have been struggling with this error.

I'm trying to test the Card::toString method but everytime I call it from deck.cpp I get an error.

Upvotes: 2

Views: 895

Answers (1)

bennji_of_the_overflow
bennji_of_the_overflow

Reputation: 1133

This line here is not correct:

string st = deck[2].toString;

The proper way to call a function in C++ (actually Java too I thought) is this:

string st = deck[2].toString();

Upvotes: 3

Related Questions