#includess at runtime?

is it possible to do something *like* below..

if(userSelection == mathFunctions)
#include <math.h>

i'm curious if you can add headers at runtime, more or less
I woudln't know a good work around for this, but for what you are asking, no..

#include is not part of the programming language. It doesn't get turned into executable code in the final program

#include is a compiler directive. It tells the compiler at the time of compling the program to insert the code in that header or file into this point of the source code.

e.g. If I had a file named myfile.h that looked like this:
1
2
3
const int mynum = 30;
const int num2 = 45;
int * myarr = new array[10];


then in the main.cpp file i had:
1
2
3
4
5
6
7
#include "myfile.h"

int main ()
{
   cout << mynum << " " << num2 << endl;
   return 0;
}


The compiler will at compile time, insert the file into the main.cpp making this:
1
2
3
4
5
6
7
8
9
const int mynum = 30;
const int num2 = 45;
int * myarr = new array[10];

int main ()
{
   cout << mynum << " " << num2 << endl;
   return 0;
}


And then compile it.
You can't compile the code at run time or include any code at run time. But yeah you can link at run time throught dll's. Load the dll, when it is required.


You can't compile the code at run time or include any code at run time. But yeah you can link at run time throught dll's. Load the dll, when it is required.


I can't find your purpose!
You just need't do it!
Using the precomplier command will finish it!
But

for what you are asking, no..

Topic archived. No new replies allowed.