|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
Question about C++ inheritence
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
*cough* Stock *cough*
|
#ifndef PERSON_H
#define PERSON_H class person { string name; string NRIC; int age; public: void GetName(string n); void GetNRIC(string nric); void GetAge(int a); string ReturnName() const; string ReturnNRIC() const; int ReturnAge() const; virtual void printName() const=0; virtual void PrintNRIC() const=0; virtual void printAge() const=0; person(string n="person",string nric="S1234567Z",int a=100); }; #include "person.h" #ifndef STUDENT_H #define STUDENT_H class student ublic person{ string AdminNo; public: void GetAdminNo(string a); string ReturnAdminNo() const; void printName() const; void PrintNRIC() const; void printAge() const; void PrintAdminNo() const; student(string n="student",string nric="S8954443C",int a=10,string admin="071234Z"); }; #endif I want to make a database that can store 5 sets of data from either person class or student class, is that possible?
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||
|
First Time Build
|
Define database in this case?
__________________
|
|||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
Programmer
|
I'm not quite sure what you mean by database, but I'm assuming you want to store objects, or pointer to objects to both people and students. You could do this by making all objects of type person. (I don't know if you know all this, so I'll go through it a little bit anyways). You could do something like:
Code:
Person *studentPtr = new Student("John", "nric12345", 15, "123456789");
Person *personPtr = new Person();
add_to_database(studentPtr);
add_to_database(personPtr);
Code:
studentPtr->PrintAdminNo(); In terms of making a database that can store it... Basically you'll need to store pointers to objects of type person, and load it with ptrs to persons and students. Other than that I don't know what you mean by database.
__________________
Whats this folding I've been hearing about? Crucial Ballistix Club ![]() Member of the OCN Diablo III Club ~M Hail to the Victors M~
|
|||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
*cough* Stock *cough*
|
Woot! Problem solved, the correct way was to do it using polymorphism (pointers to class), like kdbolt70 had said
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz
|
|||||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||
|
PC Gamer
|
icyblizard, are you taking A-Levels computing?
__________________
I am 38% addicted to Counterstrike. What about you? Battlefield 2 Stats http://bf2s.com/player/45151346/ Battlefield 2142 Stats http://www.2142-stats.com/Dj_Ariff+stats.html
|
||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||||
|
*cough* Stock *cough*
|
No, im taking a diploma in Digital Entertainment Technology. It involves alot of programming for either CG or games. 3 of my current subjects are C++ related
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz
|
|||||||||||||
|
|
|
|
|
#7 (permalink) | ||||||||||||
|
PC Gamer
|
I see. When i was doing my A-Levels practical using C++, i had like only 2 hours of sleep everyday for 3 and and half months! Anyway, just keep on practicing man! Good luck!
![]()
__________________
I am 38% addicted to Counterstrike. What about you? Battlefield 2 Stats http://bf2s.com/player/45151346/ Battlefield 2142 Stats http://www.2142-stats.com/Dj_Ariff+stats.html
|
||||||||||||
|
|
|
|
|
#8 (permalink) | |||||||||||||
|
*cough* Stock *cough*
|
Ooh, thanks
![]()
__________________
Behold : the lousiest processor in this forum! P4 2.4GHz
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|