Skip to main content
GameDev.net gamedev.net
🔒 Locked

HEADER AND PROTOTYPES

Started by blue-ice2002 Jan 1, 2003 at 4:57 PM 2 replies 150+ views
Original Post
blue-ice2002
blue-ice2002
I WONDER WHY FOR A CLASS WE USE 2 FILES.HEADER FOR PROROTYPE AND CPP FOR THE DEFINITIONS.I MEAN WHAT happens if i write the functions definition in the header file too.instead of doing void aclass::member_a(){ //code here } in .cpp /is there an adventage of this or its used in includes for not getting errors with redefinition or something.and i have another question when i create a class in a cpp to see it in another header file i do extern thename i created /but in another cpp i cant do extern cause i include the header i used extern in the other cpp i want to use that class too.so it gives error in extern line.please help me...thanks
Metal Typhoon
Metal Typhoon
quote:
Original post by blue-ice2002
I WONDER WHY FOR A CLASS WE USE 2 FILES.HEADER FOR PROROTYPE AND CPP FOR THE DEFINITIONS.I MEAN WHAT happens if i write the functions definition in the header file too.instead of doing void aclass::member_a(){
//code here
}

in .cpp /is there an adventage of this or its used in includes for not getting errors with redefinition or something.and i have another question when i create a class in a cpp to see it in another header file i do extern thename i created /but in another cpp i cant do extern cause i include the header i used extern in the other cpp i want to use that class too.so it gives error in extern line.please help me...thanks


nothing happens.. just a matter of organization
Metal Typhoon
Zorak
Zorak
If you have the function code in the header, you will sooner or later get link errors alá "function is already define in object object.obj". Since you define it once every time you include the file.
Domine non secundum peccata nostra facias nobis

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.