1

i have some code like this:

// Factory.h

template <typename TFactoryTable, typename TBaseProduct>
class FactoryTable {
public:
    static TFactoryTable instance;
};

template <typename TFactoryTable, typename TBaseProduct>
TFactoryTable FactoryTable<TFactoryTable, TBaseProduct>::instance;

// Foo.h

class BaseFoo {};
class FooFactoryTable : public FactoryTable<FooFactoryTable, BaseFoo> {};

// Bar.h

class BaseBar {};
class BarFactoryTable : public FactoryTable<BarFactoryTable, BaseBar> {};

// main.cpp

void test() {
    auto& t = FooFactoryTable::instance;
}

i put the define of static member "instance" in FactoryTable<>, so that, i can force factory tables (FooFactoryTable, BarFactoryTable,...) to use the same way to define it's singleton. these code compiled well by visual studio 2012(v110), but the editor (IntelliSense not compiler) report an error on FooFactoryTable::instance in test():

Error: class "FooFactoryTable" has no member "instance"

if i change the declaration & definition of instance to be of type "FactoryTable" (not TFactoryTable), then the editor won't report the error. so i worry that, is this (compile well) a msvc only feature, or a standard c++ feature? because the code's target platform is android and iphone, and need to be compiled by gcc.

4

1 に答える 1

1

Intellisense は、より複雑な構造 (特にプリプロセッサまたはテンプレート) によって簡単に混乱し、偽のエラーを報告するのが好きです。このように。静的メンバー型として使用するコードTFactoryTableは、100% 正当な C++ です。

于 2013-10-02T08:13:48.963 に答える