Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

shakazed

MVC question!

This topic is 6110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I´m fairly new to MVC and C++ programming and I was wondering how you can split up ypur code into different files. I´ve seen that code can be divided into different .cpp files. And how do you know which will be the main executable? As I said I´m fairly new to MVC and C++ so please don´t taunt me <>

Share this post


Link to post
Share on other sites
Advertisement
you can have as many files as you want, but just one main or WinMain function for program, its just a matter of putting all your prototypes and defines in header files (.h,.hpp) as many as you want, and implement those functions in code files (.c,.cpp) of course make sure you #include the necesary headers on your code files. then link all your object (.o,.obj) files together.

Share this post


Link to post
Share on other sites
There is no "main executable". Where ever the main function is is where the entry point is. An example:
  
/* MyFile.c */

#include "Other.h"


int main(void) {
TheOtherFunction();
return 0;
}

/* Other.h */
#ifndef INCLUDED_OTHER_H

#define INCLUDED_OTHER_H


extern void TheOtherFunction(void);

#endif

/* Other.cpp */


#include <stdio.h>


void TheOtherFunction(void) {
printf("Fish!\n");
}


[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Each time you build your project, there are actually 3 things happening:

- preprocessing
- compiling
- linking

First, the preprocessor looks at your cpp files for things like:


#define CONSTANT 1


If anywhere in your code you use CONSTANT, it gets replaced by 1.


#include "header.h"


...is something similar, the entire contents of the file 'header.h' is copied to the location of the include statement. Note that a header usually doesn't contain any function definitions, it just declares functions that are defined in some other cpp file, like forward declarations.

After the preprocessor is done, the compiler steps in. The compiler takes all your cpp files and translates them into machine code, it creates an .obj file, an object file, for every cpp file you have. The preprocessor copied all the headers into the right places, so even though you use function X() from one cpp file in another cpp file, the compiler won't complain because it knows that X() will exist at some other place.

So you end up with a bunch of machine code in several different object files. The linker takes all the object files and combines them into one executable.

The compiler knows which function is to be called when your program is started because it has a predefined name, usually main().


For header/source file organization take a look at Null and Voids example, the #ifndef/#define/#endif is needed to prevent the header contents from being included twice.

Edited by - kvh on December 30, 2001 7:32:10 PM

Share this post


Link to post
Share on other sites
Since noone else mentioned it : What you are referring to is called MFC(for Microsoft Foundation Classes). The acronym MVC usually refers to Model-View-Controller, which is a commonly used design pattern.

Fantastic doctrines (like Christianity or Islam or Marxism or Microsoft-bashing) require unanimity of belief. One dissenter casts doubt on the creed of millions. Thus the fear and hate; thus the torture chamber, the iron stake, the gallows, the labor camp, the psychiatric ward - Edward Abbey

Share this post


Link to post
Share on other sites
quote:
Original post by Arild Fines
Since noone else mentioned it : What you are referring to is called MFC(for Microsoft Foundation Classes). The acronym MVC usually refers to Model-View-Controller, which is a commonly used design pattern.

Actually, I thought he was refering to MSVC (for Microsoft Visual C++) but with Microsoft collapsed into a single M. Either way, he has his answer now.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!