English 中文(简体)
错误:预期的构造、脱轨或(或)变型之前的类型
原标题:error: expected constructor, destructor, or type conversion before ( token
最佳回答

这里是你们如何获得你们想要的东西。 (没有使用你的代码,确切地说,包括头盔等) 赞成:

// bullet_registry.hpp
class bullet;

struct bullet_registry
{
    typedef bullet* (*bullet_factory)(void); 

    std::map<std::string, bullet_factory> mFactories;
};

bullet_registry& get_global_registry(void);

template <typename T>
struct register_bullet
{
    register_bullet(const std::string& pName)
    {
        get_global_registry().mFactories.insert(std::make_pair(pName, create));
    }

    static bullet* create(void)
    {
        return new T();
    }
};

#define REGISTER_BULLET(x) 
        namespace 
        { 
            register_bullet _bullet_register_##x(#x); 
        }

// bullet_registry.cpp
bullet_registry& get_global_registry(void)
{
    // as long as this function is used to get
    // a global instance of the registry, it s
    // safe to use during static initialization
    static bullet_registry result;

    return result; // simple global variable with lazy initialization
}

// bullet.hpp
struct my_bullet : bullet { };

// bullet.cpp
REGISTER_BULLET(my_bullet)

这样做的办法是形成一个全球性的变量,在静态初始阶段,这一变量将在某个时候启动。 发生这种情况时,在其建筑商中,它可以查阅全球登记册,并以名称和制造子弹的功能登记。

由于静态初始化令没有明确规定,我们把全球管理人置于一种职能之下,因此,当这一职能被首次称作是按要求和使用的。 这使得我们无法使用一个未初创的管理人,如果这只是一个简单的全球目标,情况就是如此。

自由要求澄清。

问题回答

我不认为你可以要求职能之外的职能(只要你不利用结果来开始全球工作)。

<>代码>()为功能。 您可以不设范围地称职。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签