Let's say you have a main() file, 8 separate cpp files, and 8 corresponding header files (that represent classes, of course) Is it possible to assign each cpp file a different namespace, say namespace na for class a, and then namespace nb for class b, and so on?
#include <iostream>
#include <fstream>
#include <sstream>
#include <new>
#include <math.h>
#include <time.h>
#define g 9.8
#include "include/intro.h"
#include "include/Labone.h"
usingnamespace std;
Labone e [5]; //Getting ready to make 5 instances of the class Labone
//Setting all elements of the array to instances...
for (int n = 0; n<5;n++)
{
e[n] = Labone(n);
} //end initializer
namespace na
{
e[0].etitlea();
for (int nu = 0; nu<5;nu++)
{
e[nu].adata(nu);
} //end data handler a
e[0].etitleb();
for (int num = 0; num<5; num++)
{
e[num].getaccel();
e[num].bdata(num);
e[num].setaccel();
} //end data handler b
e[0].analysis();
} //end namespace
int main()
{
int x;
string mystr;
cout << "Welcome to the Physics Lab Program!"<<endl;
cout<<'\n'<<"The labs for this course that there are programs for are as follows: "<<endl;
cout<<'\n'<<"1 - 1D Kinematics"<<endl;
cout<<"3 - Newton's Laws"<<endl;
cout<<"4 - Friction"<<endl;
cout<<"5 - Work and Energy"<<endl;
cout<<"6 - Collisions"<<endl;
cout<<"7 - Torque"<<endl;
cout<<"8 - Simple Harmonic Motion"<<endl;
cout<<"9 - Fluids"<<endl;
cout<<'\n'<<"Please make your selection: ";
getline(cin,mystr);
stringstream(mystr)>>x;
return 0;
} //end main
I am trying to call the class Labone (and its functions) how I normally would if this were one file, when the user inputs 1.
I know that's the case, and I know that is the standard namespace, which is associated with entities created with iostream. I am trying to use different namespaces to handle any problems with coincidence of variable names. I am trying to do something like what is shown here, but with classes: http://www.cplusplus.com/doc/tutorial/namespaces/
It doesn't generate any compile errors! At least none concerning this. It is, however, generating errors as to the empty files I have, and simply "complains all the way down" after I remove them from the project. Why is this? Better yet, never mind. I have decided not to use different namespaces for different classes. The variables are all private (last time I checked), so there is no need!
I am now trying to put them all into one big program, which has been done for the most part (on every program except the final version of the one I was creating in this thread; this one isn't included because I am trying to make its data depend less on intro(), a common class for all the other programs. I am trying to do this while maintaining structure.) Here is my .cpp file (sorry for posting the entire file):