-1

Please help, I have these lines of code:

#ifndef UNTITLED_ARMY_H
#define UNTITLED_ARMY_H

using namespace std;

#include <vector>

class Country {

public:

    vector <DiplomacyRequest> pendingDiplomacy;  //Line 12

    Country() {} } ;

class DiplomacyRequest {

    Country issuerCountry;

    int money = 0;

    void acceptRequest();
    void declainRequest();

public:
    DiplomacyRequest() {} };

#endif //UNTITLED_ARMY_H

and I've been provided with an error:

error: use of undeclared identifier 'DiplomacyRequest', at line 12

Where is the fault?

Oscar
  • 123
  • 6
  • You need to forward declare DiplomacyRequest. Read more [here](http://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c) – Virtually Real Feb 01 '17 at 23:21

1 Answers1

0

You're referring to DiplomacyRequest in line 12 before declaring it. You can use a forward-declaration to fix the issue, as std::vector is guaranteed to work with incomplete types.

class DiplomacyRequest;

class Country
{

public:
    vector<DiplomacyRequest> pendingDiplomacy; // Line 12

    Country()
    {
    }
};

class DiplomacyRequest
{

    Country issuerCountry;

    int money = 0;

    void acceptRequest();
    void declainRequest();

public:
    DiplomacyRequest()
    {
    }
};

wandbox example

Community
  • 1
  • 1
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416