Hi everyone!
I must admit, I'm not up to date with the series and I haven't watched enough of them to get passed the initial platform layer work. Because of this I don't know how multiple files are handled - other than what Casey explained about compiling a single file and including all others directly instead of through the use of header files.
I've started experimenting with some simple stuff and ignoring graphics, so basically just console output and I'm immediately finding it difficult. My problem is that I'm stuck thinking in OOP. Can someone who is a bit more used to thinking non-OOP help me with a simple example?
Let's say I have BobTheMiner, BobsWife and BobsDaughter and I want each one to be able to say something. I want to put each ones code in seperate files to make it more manageable so I do
| #include "Bob.cpp"
#include "BobsWife.cpp"
#inclide "BobsDaugther.cpp"
int main() {
// call each method from each file
}
|
Then what? My initial thought was to create one method each like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | //Bob.cpp
char* BobSays(){
return "Bob says: I'm hungry again";
}
//BobsWife.cpp
char* BobsWifeSays(){
return "Bobs Wife says: I want to take a walk";
}
//BobsDaughter.cpp
char* BobsDaughterSays(){
return "Bobs Daughter says: I love my fluffy cat";
}
|
But then I thought that maybe it would be best to just create a struct and put the sentence in the struct so that each person is represented by a struct and then there is one method that takes a struct and produces the sentence.
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | struct Person{
char* name;
char* sentence;
}
char* PersonSays(Person* p){
return concatenation of p->name and p-> sentence;
}
//Bob.cpp
Person *bob = //allocate memory and set name and sentence
//BobsWife.cpp
Person *wife = //allocate memory and set name etc.
|
That seems like it's more in line with the Data->transform->newData mentality of data driven design. I'm I on the right path here?
/Robert