cactusbin
cactusbin

Reputation: 681

Can't declare object

I am getting an error on this line:

Attack a("Nothing", 60, Magic);

Here is the error:

..\main.cpp:11: error: expected `;' before "a"
..\main.cpp:11: warning: statement has no effect

Here are the relevant files: main.cpp:

#include "Attack.h"

int main() {
    Attack a("Nothing", 60, Magic);

    return 0;
}

Attack.h:

#ifndef ATTACK_H_
#define ATTACK_H_

#include <string>
#include <stdlib.h>
#include <time.h>

enum ATTACK_ATTRIBUTE {
    Attack, Speed, Magic
};

class Attack {
private:
    std::string name;
    int power; //Out of 10
    ATTACK_ATTRIBUTE attribute;

public:
    Attack(std::string name, int power, ATTACK_ATTRIBUTE attribute);
    virtual ~Attack();

    std::string getName();

    ATTACK_ATTRIBUTE getAttribute();

    int getPower();
};

#endif /* ATTACK_H_ */

Upvotes: 2

Views: 95

Answers (3)

Gian
Gian

Reputation: 13945

You have a class and an enumerator both called 'Attack'. Try changing one of the names to something else.

Upvotes: 5

Loki Astari
Loki Astari

Reputation: 264381

The enum value Attack is in the same namespace as Attack the class and they are conflicting.

Upvotes: 2

James Smith
James Smith

Reputation: 69

You have defined your Attack class in a header file but I don't see an implementation for it. Don't you need to implement the class methods?

Upvotes: -1

Related Questions