Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct First {
- uint type = 0;
- int data;
- this( int d ) {
- data = d;
- }
- }
- struct Second {
- uint type = 1;
- double data;
- this( double d ) {
- data = d;
- }
- }
- First returnFirst( int data ) {
- return First( data );
- }
- Second returnSecond( double data ) {
- return Second( data );
- }
- void printAny( uint * type ) {
- if( *type == 0 ) {
- writeln( (cast(First *)type).data );
- } else if( *type == 1 ) {
- writeln( (cast(Second *)type).data );
- } else {
- writeln( "Error" );
- }
- }
- int main() {
- printAny( &returnFirst( 42 ).type );
- printAny( &returnSecond( 3.14 ).type );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement