error: expected constructor, destructor, or type conversion before '(' token

Posted by jonathanasdf on Stack Overflow See other posts from Stack Overflow or by jonathanasdf
Published on 2010-04-11T20:38:59Z Indexed on 2010/04/11 20:43 UTC
Read the original article Hit count: 331

Filed under:
|
|
|

include/TestBullet.h:12: error: expected constructor, destructor, or type conver sion before '(' token

I hate C++ error messages... lol ^^

Basically, I'm following what was written in this post to try to create a factory class for bullets so they can be instantiated from a string, which will be parsed from an xml file, because I don't want to have a function with a switch for all of the classes because that looks ugly.

Here is my TestBullet.h:

#pragma once

#include "Bullet.h"
#include "BulletFactory.h"

class TestBullet : public Bullet {
public:
    void init(BulletData& bulletData);
    void update();
};

REGISTER_BULLET(TestBullet);  <-- line 12

And my BulletFactory.h:

#pragma once

#include <string>
#include <map>
#include "Bullet.h"

#define REGISTER_BULLET(NAME) BulletFactory::reg<NAME>(#NAME)
#define REGISTER_BULLET_ALT(NAME, CLASS) BulletFactory::reg<CLASS>(NAME)

template<typename T> Bullet * create() { return new T; }

struct BulletFactory {
    typedef std::map<std::string, Bullet*(*)()> bulletMapType;
    static bulletMapType map;

    static Bullet * createInstance(char* s) {
        std::string str(s);
        bulletMapType::iterator it = map.find(str);
        if(it == map.end())
            return 0;
        return it->second();
    }

    template<typename T> 
    static void reg(std::string& s) { 
        map.insert(std::make_pair(s, &create<T>));
    }
};

Thanks in advance.

© Stack Overflow or respective owner

Related posts about c++

Related posts about factory