Class prototyping?

Can i do that? Like, at the start I make a class called Calculate with function prototypes like multiply, add, etc. Then at the end of the program I put the class again with the full functions.

I want to know if there's a way to do this correctly, or more correctly than in other way, etc.
Last edited on
You can define the class and later define the member functions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Class definition
class Calculate
{
public:
	int multiply(int, int) const;
};

...

// Member function definitions
int Calculate::multiply(int a, int b) const
{
	return a * b;
}
Hm, but I want the code to be "organized", and put my full functions inside a class. Can I do that? The class functions laying around together in my program don't look good.

And what does "const" do before ending the statement after the function? Does that mean it can only be defined once later in the program?
Last edited on
It is organized the way Peter87 did it. Normally, you would put the function prototypes in a header file.

The const mean there, that this function is not allowed to modify values.
You can't repeat the class definition.

Often the class code is organized by putting the class definition into a header file that other files that use the class can include. All the member functions are defined in a source file. So if the class is named Calculate you might want to name the files Calculate.h and Calculate.cpp respectively.

const here means that the function will not modify any data members of the object the function is called on.
Last edited on
Oh, ok, so this is perfect! I needed to remake my code using headers and i didn't know where to start from.

One more last thing: What does happen if I put const before declaring a function? Like "const void CoutNumber (int Number) {/*blah*/}".
Last edited on
One more last thing: What does happen if I put const before declaring a function?

It returns a const value, but const void doesn't make sense to me.
Topic archived. No new replies allowed.