0

I am just new to C++, so bear with me. Inside my class, MyArena, I made a vector of pointers, fighters, of another class, Fighter. With this vector, I am collecting Fighter pointers and calling functions for them. But I keep getting errors for fighters.

#include <vector>

using namespace std;
class Fighter;

class MyArena {

    vector<Fighter*> fighters;
    int current_size = 0;

    bool MyArena :: addFighter(string info){

        for (int i = 0; i < 11; i++){
            if (fighters[i]->getName() == n) //error that "point to incomplete pass type is not allowed?"
                isLegit = false;
        }

        fighters.push_back(new Fighter(n, t, mH, st, sp, m)); //"Fighter" is incomplete type?
        return true;
    }

    bool removeFighter(string name){
        for (int i = 0; i < 11; i++){
            if (fighters[i]->getName() == name)//error that "point to incomplete pass type is not allowed?"
                fighters[i] = NULL;
        }
    }

};

How should I approach this?

2
  • 1
    Fighter is not defined. Move the member function definitions out of the header and into a .cpp file. Commented Sep 5, 2014 at 23:32
  • 3
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers See: How to create a Minimal, Complete, and Verifiable example. Commented Sep 5, 2014 at 23:33

1 Answer 1

1

You forward declare the class here:

class Fighter;

But you never included the file. Put this after your other include

#include "Fighter.h"

Or a relative path to get to Fighter.h if it is in a different folder.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, I forgot to #include the class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.