Last active
June 11, 2016 12:12
-
-
Save otaks/0b4ec7281479b2aa78f85ca079536e46 to your computer and use it in GitHub Desktop.
c keisho
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AnimalP.h" | |
int Animal_init(Animal animal, char* name) { | |
memset( animal->name, 0x00, sizeof( animal->name ) ); | |
strcpy( animal->name, name ); | |
} | |
int Animal_done( Animal animal ) { | |
/* do nothing */ | |
} | |
void Animal_sayName( Animal animal ) { | |
printf( "%s\n", animal->name ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
typedef struct animal* Animal; | |
void Animal_sayName( Animal animal ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "Animal.h" | |
struct animal { | |
char name[ 20 ]; | |
}; | |
int Animal_init( Animal animal, char* name ); | |
int Animal_done( Animal animal ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include "dog.h" | |
#include "AnimalP.h" | |
struct dog { | |
struct animal; //スーパークラスは構造体の一番上に定義 | |
//以降犬クラス固有のメンバ | |
}; | |
Dog Dog_create( char* name ) { | |
Dog t = calloc( sizeof( struct dog ) ,1); | |
Animal_init( (Animal)t, name ); | |
return t; | |
} | |
void Dog_berg( Dog dog ) | |
{ | |
printf( "wan!!\n" ); | |
} | |
void Dog_delete( Dog dog ){ | |
Animal_done( ( Animal )dog ); | |
free( dog ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <stdio.h> | |
typedef struct dog* Dog; | |
Dog Dog_create( char* ); | |
void Dog_berg( Dog ); | |
void Dog_delete( Dog ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "animal.h" | |
#include "dog.h" | |
int main() { | |
Dog one = Dog_create("lewis"); | |
Dog two = Dog_create( "mike" ); | |
Animal_sayName( ( Animal )one ); | |
Animal_sayName( ( Animal )two ); | |
Dog_delete( one ); | |
Dog_delete( two ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment