Im still trying to get the hang of linking functions and their constructors to other files. Im trying to link this header file to another cpp file, which i will eventually add to yet another cpp file. Can I get an explanation as to what I am doing wrong? Help is greatly appreciated. Thanks.
Header: Functions.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Header for Functions.cpp
#ifndef FUNCTIONS_h_INCLUDED
#define FUNCTIONS_h_INCLUDED
class Leveler
{
public:
int levels(int& level);
private:
double build;
double constant;
double determinant;
double total;
int exp[100];
};
#endif
In my .cpp im getting "Error: member function 'Leveler::levels' may not be redeclared outside its class." And just below that on the bracket im getting "Error: expected a ';'"
I've had similar problems, but i've actually been able to get around them.
How can I call/link my functions from the cpp file, Functions.cpp, to another cpp file? My header file, Functions.h, has the function declarations, where as Functions.cpp has the directions/contents. I could really use some help. Thanks.
I'm using Microsoft Visual Studio 2010. And I have included Functions.cpp. I even tried including both Functions.h and Functions.cpp, then just Functions.h, and still there are errors.
This demonstrates a fundamental misunderstanding of what a class is. The function levelGain is a member function of the class Leveler. You must first make an object of type Leveler, and then you can call its functions:
Like I stated above, I'm still pretty new to this. The only thing related to classes that I've worked with are structs, and even then the work dealing with that in my first programming course was quite tedious.
Thanks again for the tips on how to do this. One last thing I would like to ask; would this stuff I'm working on now be considered "object oriented" and more directed toward C#? Thanks again.
Edit: Dont get me wrong, im not trying to confuse words. I've just recently heard about object oriented programming and wanted to find out if this met the match.
In C++ a struct and a class are identical, except for default member visibility (public vs. private).
"Object oriented" is one of a number of ambiguously defined terms, freuqently used as a poorly-defined buzzword. You can code in C++ in an "Object oriented" way, and you can code in C# in an "Object oriented" way.
Thanks for clearing that up. I never understood why people used that reference when it seems as though C++ is just as capable and applicable in definition and application. However, I have yet to use C#; im sure there is some sort of difference.