Xnyper
February 15th, 2008, 12:42 PM
I am taking a C++ class, and since I'm a Linux user (though just recently) I decided that I should be able to do everything, and more, that the windows users in the class can do, on my Ubuntu box. Not only that, but I can do it with style--command line style. I've been writing the code in vim, and compiling it with g++. No problems until now.
I have succeeded in compiling the object separately
g++ -c classNameImp.cpp
and then compiling my code and linking it with said object
g++ -Wall progName.cpp className.o
(forgive me if my syntax is slightly inaccurate, I had it right at the time, but don't have anything to compile right now--so I can't test the validity of my examples. I assume you get the idea.)
My teacher has us use, in situations like the one above, three separate files. There is the header file (className.h), the implementation file (classNameImp.cpp), and the program file (progName.cpp, this one includes main() ) I'm not sure if this is standard procedure or not, so I thought I'd make note of it. Also, since its an online class I don't spend much time communicating about code, its just me and the book, so if I say something in a weird way, please let me know.
OK, to question 1.
Say I have a class "point"
and another, "circle"
I want to use an object of type: point in my definition for the class circle (specifically as its centerpoint.) a.k.a class composition.
I will make a program called "test" to test these classes.
I know that I need to #include"circle.h" at the top of test.cpp, but where do I #include point.h? Does it go in circle.h? circleImp.cpp? both?
also, when compiling this, do I compile circleImp.cpp and pointImp.cpp separately (using "g++ -c <filename>") or can I compile them both into one object, or will the compiler know to include the information for the class: "point" when I compile the circle.cpp based on the #include statements?
Finally, if I do compile the classes into separate *.o files, what is the syntax of the g++ command to link multiple objects?
My book spends 4 pages on class inheritance and less than a paragraph on class composition--and my teacher is lost without her beloved windows-based IDE. So as you can imagine, its a tricky thing to stumble through on your own. Thanks for your help,
I have succeeded in compiling the object separately
g++ -c classNameImp.cpp
and then compiling my code and linking it with said object
g++ -Wall progName.cpp className.o
(forgive me if my syntax is slightly inaccurate, I had it right at the time, but don't have anything to compile right now--so I can't test the validity of my examples. I assume you get the idea.)
My teacher has us use, in situations like the one above, three separate files. There is the header file (className.h), the implementation file (classNameImp.cpp), and the program file (progName.cpp, this one includes main() ) I'm not sure if this is standard procedure or not, so I thought I'd make note of it. Also, since its an online class I don't spend much time communicating about code, its just me and the book, so if I say something in a weird way, please let me know.
OK, to question 1.
Say I have a class "point"
and another, "circle"
I want to use an object of type: point in my definition for the class circle (specifically as its centerpoint.) a.k.a class composition.
I will make a program called "test" to test these classes.
I know that I need to #include"circle.h" at the top of test.cpp, but where do I #include point.h? Does it go in circle.h? circleImp.cpp? both?
also, when compiling this, do I compile circleImp.cpp and pointImp.cpp separately (using "g++ -c <filename>") or can I compile them both into one object, or will the compiler know to include the information for the class: "point" when I compile the circle.cpp based on the #include statements?
Finally, if I do compile the classes into separate *.o files, what is the syntax of the g++ command to link multiple objects?
My book spends 4 pages on class inheritance and less than a paragraph on class composition--and my teacher is lost without her beloved windows-based IDE. So as you can imagine, its a tricky thing to stumble through on your own. Thanks for your help,