help Implementing Object Oriented ansi-C approach??
- by No Money
Hey there,
I am an Intermediate programmer in Java and know some of the basics in C++. I recently started to scam over "C language" [please note that i emphasized on C language and want to stick with C as i found it to be a perfect tool, so no need for suggestions focusing on why should i move back to C++ or Java]. Moving on, I code an Object Oriented approach in C but kindda scramble with the pointers part. Please understand that I am just a noob trying to extend my knowledge beyond what i learned in High School. Here is my code.....
#include <stdio.h>
typedef struct per{
int privateint;
char *privateString;
struct per (*New) ();
void (*deleteperOBJ) (struct t_person *);
void (*setperNumber) ((struct*) t_person,int);
void (*setperString) ((struct*) t_person,char *);
void (*dumpperState) ((struct*) t_person);
}t_person;
void setperNumber(t_person *const per,int num){
if(per==NULL) return;
per->privateint=num;
}
void setperString(t_person *const per,char *string){
if(per==NULL) return;
per->privateString=string;
}
void dumpperState(t_person *const per){
if(per==NULL) return;
printf("value of private int==%d\n", per->privateint);
printf("value of private string==%s\n", per->privateString);
}
void deleteperOBJ(struct t_person *const per){
free((void*)t_person->per);
t_person ->per = NULL;
}
main(){
t_person *const per = (struct*) malloc(sizeof(t_person));
per = t_person -> struct per -> New();
per -> setperNumber (t_person *per, 123);
per -> setperString(t_person *per, "No money");
dumpperState(t_person *per);
deleteperOBJ(t_person *per);
}
Just to warn you, this program has several errors and since I am a beginner I couldn't help except to post this thread as a question. I am looking forward for assistance. Thanks in advance.