Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
int main (void) { GX::CfgFile cfg("data\\config.cfg"); cfg.parse(); std::string a = cfg["Section"]["eins"]; return (0); } |
Alter Hase
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
class TRIBASE_API tbVector3 { public: // Variablen union { struct { float x; // Koordinaten float y; float z; }; struct { float u; // Texturkoordinaten float v; float w; }; float c[3]; // Array der Koordinaten D3DVECTOR vD3DVector; // Vektor in Form eines Direct3D-Vektors }; ... }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
#include <iostream> #include <vector> #include <algorithm> struct ini_item_base { virtual ~ini_item_base() = 0; virtual operator int() const { throw std::bad_cast( "cannot cast to int" ); } virtual operator std::string() const { throw std::bad_cast( "cannot cast to string" ); } // Weitere konvertierungs operatoren }; ini_item_base::~ini_item_base() {} template< typename T > struct ini_item; template<> struct ini_item< int > : ini_item_base { int value; ini_item( int val ) : value( val ) {} operator int() const { return value; } // Weitere konvertierungs operatoren }; template<> struct ini_item< std::string > : ini_item_base { std::string value; ini_item( std::string val ) : value( val ) {} operator std::string() const { return value; } // Weitere konvertierungs operatoren }; namespace { struct deleter { template< typename T > void operator()( T*& ptr ) { delete ptr; ptr = 0; } }; } struct foo { typedef std::vector< ini_item_base* > list_type; foo() { // Mal zwei Beispieleintraege list.push_back( new ini_item< int >( 100 ) ); list.push_back( new ini_item< std::string >( "Hallo Welt" ) ); } ~foo() { std::for_each( list.begin(), list.end(), deleter() ); } const ini_item_base& operator[]( int x ) const { return *list.at( x ); } private: list_type list; }; int main() { foo x; int y; std::string z; try { y = x[ 0 ]; z = x[ 1 ]; // std::string blubb = x[ 0 ]; // <- Wirft ein std::bad_cast } catch ( std::bad_cast& e ) { std::cout << "Exception: " << e.what() << std::endl; } std::cout << y << " " << z << std::endl; std::cin.get(); } |
Zitat von »"grek40"«
Ich dachte schon meine Idee wäre kompliziert :lol:
Werbeanzeige