Note that there are some explanatory texts on larger screens.

plurals
  1. POerror: expected constructor, destructor, or type conversion before '(' token
    text
    copied!<pre><code>include/TestBullet.h:12: error: expected constructor, destructor, or type conver sion before '(' token </code></pre> <p>I hate C++ error messages... lol ^^</p> <p>Basically, I'm following what was written in <a href="https://stackoverflow.com/questions/582331/c-is-there-a-way-to-instantiate-objects-from-a-string-holding-their-class-name/582456#582456">this post</a> 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.</p> <p>Here is my TestBullet.h:</p> <pre><code>#pragma once #include "Bullet.h" #include "BulletFactory.h" class TestBullet : public Bullet { public: void init(BulletData&amp; bulletData); void update(); }; REGISTER_BULLET(TestBullet); &lt;-- line 12 </code></pre> <p>And my BulletFactory.h:</p> <pre><code>#pragma once #include &lt;string&gt; #include &lt;map&gt; #include "Bullet.h" #define REGISTER_BULLET(NAME) BulletFactory::reg&lt;NAME&gt;(#NAME) #define REGISTER_BULLET_ALT(NAME, CLASS) BulletFactory::reg&lt;CLASS&gt;(NAME) template&lt;typename T&gt; Bullet * create() { return new T; } struct BulletFactory { typedef std::map&lt;std::string, Bullet*(*)()&gt; 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-&gt;second(); } template&lt;typename T&gt; static void reg(std::string&amp; s) { map.insert(std::make_pair(s, &amp;create&lt;T&gt;)); } }; </code></pre> <p>Thanks in advance. </p> <p>And unrelated to the error, but is there a way to let Bullet include BulletFactory without creating tons of errors (because of circular inclusion)? This way I would be able to remove <code>#include "BulletFactory.h"</code> from the top of all of the bullet subclasses.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload