From 80dafbe5b1ed5b8d574d37a55954cb56ddac19d4 Mon Sep 17 00:00:00 2001 From: rjongbloed Date: Sun, 11 Jul 2004 08:33:15 +0000 Subject: [PATCH] Fixed bizarre MSVC 6 bug by making template functons in a class. --- samples/factory/main.cxx | 135 +++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 69 deletions(-) rewrite samples/factory/main.cxx (83%) diff --git a/samples/factory/main.cxx b/samples/factory/main.cxx dissimilarity index 83% index aedd0dc3..758c7c4d 100644 --- a/samples/factory/main.cxx +++ b/samples/factory/main.cxx @@ -1,69 +1,66 @@ - -#include - -#include -#include -#include - -#include "abstract.h" - -extern unsigned PTraceCurrentLevel; - -class Factory : public PProcess -{ - public: - Factory() - : PProcess() { } - void Main(); -}; - -PCREATE_PROCESS(Factory) - -template -void DisplayFactory(const char * title) -{ - cout << "Testing " << title << endl; - PFactory::KeyList_T keys = PFactory::GetKeyList(); - - cout << "keys = " << endl; - PFactory::KeyList_T::const_iterator r; - for (r = keys.begin(); r != keys.end(); ++r) { - cout << " " << *r << endl; - } - - cout << endl; -} - -template -void DisplayTestFactory() -{ - PFactory::KeyList_T keyList = PFactory::GetKeyList(); - PFactory::KeyList_T::const_iterator r; - - cout << "List of concrete types:" << endl; - for (r = keyList.begin(); r != keyList.end(); ++r) - cout << " " << *r << endl; - cout << endl; - - unsigned i; - for (i = 0; i < keyList.size(); i++) { - for (int j = 0; j < 3; j++) - { - MyAbstractClass * c = PFactory::CreateInstance(keyList[i]); - if (c == NULL) - cout << "Cannot instantiate class " << keyList[i] << endl; - else - cout << keyList[i] << "::Function returned " << c->Function() << ", instance " << (void *)c << endl; - } - } -} - -void Factory::Main() -{ - DisplayTestFactory(); - DisplayTestFactory(); - - DisplayFactory("PURLScheme"); - DisplayFactory("PTextToSpeech"); - DisplayFactory("PPluginModuleManager"); -} + +#include + +#include +#include +#include + +#include "abstract.h" + + +class Factory : public PProcess +{ + public: + Factory() + : PProcess() { } + void Main(); +}; + +PCREATE_PROCESS(Factory) + + +template +class Display +{ +public: + static void ConcreteTypes(const char * title) + { + cout << "\nConcrete types for " << title << ':' << endl; + PFactory::KeyList_T keys = PFactory::GetKeyList(); + PFactory::KeyList_T::const_iterator r; + for (r = keys.begin(); r != keys.end(); ++r) + cout << " " << *r << endl; + + cout << endl; + } + + static void TestFactory() + { + PFactory::KeyList_T keyList = PFactory::GetKeyList(); + unsigned i; + for (i = 0; i < keyList.size(); i++) { + for (int j = 0; j < 3; j++) + { + MyAbstractClass * c = PFactory::CreateInstance(keyList[i]); + if (c == NULL) + cout << "Cannot instantiate class " << keyList[i] << endl; + else + cout << keyList[i] << "::Function returned \"" << c->Function() << "\", instance " << (void *)c << endl; + } + } + } +}; + + +void Factory::Main() +{ + Display::ConcreteTypes("MyAbstractClass by PString"); + Display::TestFactory(); + + Display::ConcreteTypes("MyAbstractClass by unsigned"); + Display::TestFactory(); + + Display::ConcreteTypes("PURLScheme"); + Display::ConcreteTypes("PTextToSpeech"); + Display::ConcreteTypes("PPluginModuleManager"); +} -- 2.11.4.GIT