How do I rearrange my classes in C++?

watdahel

Golden Member
Jun 22, 2001
1,661
12
81
www.youtube.com
Can someone show me how I would separate this program into separate class files so that Box and CandyBox are two separate classes? My goal is to have Ex8_03.cpp contain only the main function. Box.cpp, Box.h, CandyBox.cpp, CandyBox.h would be the other files.

Ex8_03.cpp
 

itachi

Senior member
Aug 17, 2004
390
0
0
if you're trying to find some way to automate it.. it doesn't exist, as far as i know.

if it's the semantics you're asking for..

in the header..
class ClassName {
public:
return-type method-name(parameters) const-modifier;
];

in the source..
return-type ClassName::method-name(parameters) const-modifier {
// code body
}
 

watdahel

Golden Member
Jun 22, 2001
1,661
12
81
www.youtube.com
Clearly you're a C++ pro. You even put in comments.

I use Microsoft Visual C++ and it automatically adds preprocessor directives to my files like the one I inserted. I notice you do the same but a bit different. Why?
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
the preprocessor directives are so that if you include the same header file more than once, you don't get a complaint about the class being defined more than once. you may not think it's a problem to avoid including the same header more than once, but after you start creating a number of classes that share dependencies, you'll find it harder and harder to avoid. the preprocessor directives are just there to say that it should be processed only once.