Typelist -> hirarchie
-
Ich hab eine typelist die mehrere klassentypen enthällt, nehmen wir mal folgendes beispiel:
// the building block for typelists of any length // -> IMPORTANT: every typelist hast to end with a NullType // -> defines nested types: // head (first element, a non-typelist type by convention) // tail (second element, can be another typelist) template <class T, class U> struct Typelist{ typedef T head; typedef U hail; }; // some example types class a{ public: int a_ : 11; }; class b{ public: int b_ : 12; }; class c{ public: int c_ : 13; }; // build the typelist typedef TypeList<a, TypeList<b, TypeList<c, NullType> > > list_type;jetzt möchte ich eine klasse schreiben, welche von allen typen in der typelist erbt, ich will also anstatt:
class MyClass : public a, b, c{ };folgendes schreiben können:
class MyClass : public MagicHirarchieGenerator<type_list>{ };Es geht dabei eher um das prinzip, wie man etwas solches schreiben könnte und weniger um den anwendungszweg in einem fertigen programm.
Es ist halt mehr eine spielerei, eine selbstgestellte aufgabe, bei der ich nicht weiter komme.
-
Typlisten wie von dir gezeigt sind sowas von out. Gehe mit der Zeit und nimm C++11.
template <typename... T> struct typelist; template <typename> class MyClass {}; template <typename... T> class MyClass<typelist<T...>> : T... {}; struct a{a(){std::cout << "construct a\n";}}; struct b{b(){std::cout << "construct b\n";}}; struct c{c(){std::cout << "construct c\n";}}; int main() { using type_list = typelist<a, b, c>; MyClass<type_list> mc; } /* Ausgabe: construct a construct b construct c */
-
Gut, aus Nostalgiegründen die C++71-Version:
template <typename T> struct MagicHirarchieGenerator; template <typename H, typename T> struct MagicHirarchieGenerator<TypeList<H, T> > : H, MagicHirarchieGenerator<T> {}; template <> struct MagicHirarchieGenerator<NullType> {};hail! (Nicht falsch verstehen, das Wort steht so in gamer8o4s Code)
-
Typlisten wie von dir gezeigt sind sowas von out. Gehe mit der Zeit und nimm C++11.
oh mein gott, gut das ich das gefragt habe
jetzt schreibe ich seit 2 tagen an algorithmen für typelisten und jetzt sagst du mir, dass es in c++11 dafür variadische templates gibt...
hab das gerade mal ausprobiert, aber anscheinend kapiert das mein "visual studio 2012 express desktop" nicht. Ich lade mal die updates runter und melde mich nochmal
-
gibt immernoch einen fehler, wie gesagt ich hab es mit "visual studio 2012 express for desktop" ausgetestet, und da dass einer der neusten compiler ist , sollte es doch eigentlich funktionieren, aber naja... klappt nicht

error C2143: syntax error : missing ',' before '...'template<typename... Args> struct SomeStruct { };
-
...
-
#include <iostream> using namespace std; //#include <delta\include.h> //using namespace delta; template <typename... T> struct typelist; template <typename> class MyClass {}; template <typename... T> class MyClass<typelist<T...> > : T... {}; struct a{a(){std::cout << "construct a\n";}}; struct b{b(){std::cout << "construct b\n";}}; struct c{c(){std::cout << "construct c\n";}}; int main() { typedef typelist<a,b,c> type_list; MyClass<type_list> mc; getchar(); }fehler:
1>------ Build started: Project: AppConsole, Configuration: Debug x64 ------
1> main.cpp
1>main.cpp(7): error C2143: syntax error : missing ',' before '...'
1>main.cpp(9): error C2143: syntax error : missing ',' before '...'
1>main.cpp(9): error C2065: 'T' : undeclared identifier
1>main.cpp(9): error C2143: syntax error : missing ';' before '{'
1>main.cpp(11): error C2143: syntax error : missing ';' before '{'
1>main.cpp(12): error C2143: syntax error : missing ';' before '{'
1>main.cpp(13): error C2143: syntax error : missing ';' before '{'
1>main.cpp(15): error C2143: syntax error : missing ';' before '{'
1>main.cpp(16): error C2065: 'a' : undeclared identifier
1>main.cpp(16): error C2065: 'b' : undeclared identifier
1>main.cpp(16): error C2065: 'c' : undeclared identifier
1>main.cpp(16): error C2977: 'typelist' : too many template arguments
1> main.cpp(7) : see declaration of 'typelist'
1>main.cpp(17): error C2065: 'type_list' : undeclared identifier
1>main.cpp(17): error C2923: 'MyClass' : 'type_list' is not a valid template type argument for parameter '<unnamed-symbol>'
1>main.cpp(20): error C2143: syntax error : missing ';' before '}'
1>main.cpp(21): error C2143: syntax error : missing ';' before '}'
1>main.cpp(21): fatal error C1004: unexpected end-of-file found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Anleitung beachtet?
-
update gedownloaded
update installiert
pc neugestartet
neues projekt erstellt (win32 console application)
debug win32
code kopiert
code kompeliert
FEHLER
-
Instructions
After downloading and installing the program, you can launch Visual Studio 2012, load your C++ project and you can switch to the new compilers. We recommend you create a separate project configuration from menu Build > Configuration Manager by duplicating your existing configuration and then follow the steps below: 1.Open Project Property Pages (Alt+F7 under the Visual C++ mappings or right-click on the project in Solution Explorer) 2.From the ‘General’ tab, change ‘Platform toolset’ from ‘Visual Studio 2012 (v110)’ to ‘Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov)’ and close the Property Pages 3.Launch a full rebuild of your project
-
sorry, nicht richtig gelesen, klappt....eine frage aber noch nebenbei, lohnt nicht dafür ein thema aufzumachen

class c{ int i; int getInt() const{ return i; } };ist der zugriff auf i threadsafe? oder kann es zu fehlern kommen, wenn gleichzeitig ein anderer thread die variable ändert?
-
In solchen Situationen kann es immer zu Fehlern kommen. Thread Synchronisation ist hier definitiv erforderlich.
-
In solchen Situationen kann es immer zu Fehlern kommen. Thread Synchronisation ist hier definitiv erforderlich.
okay, habs geändert
