Class practice help

Ok im practicing using classes and i have 2 functions and i want to add one number in one function to another number in main, how do i do that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace std;

class CLASS
{
    public:
        void Function();
        void Function2(int seven);
};

int main()
{
    int seven = 7;

    CLASS ClsObj;
    ClsObj.Function();

    cout << "\n";

    CLASS ClsObj2;
    ClsObj2.Function2(seven);


}

void CLASS::Function()
{
    cout << "shit fuck" << endl;
}

void CLASS::Function2()
{
    int six = 6;

    cout << six + seven << endl;
}




C:\Users\Chay Hawk\Desktop\Classes\main.cpp|32|error: prototype for 'void CLASS::Function2()' does not match any in class 'CLASS'|
C:\Users\Chay Hawk\Desktop\Classes\main.cpp|9|error: candidate is: void CLASS::Function2(int)|
||=== Build finished: 2 errors, 0 warnings ===|
Like every other function you define, the definition must match the declaration.

1
2
void CLASS::Function2(int seven)
 // ... 


You should really stop using all caps for class and/or function names. Typically if a person sees something in all caps, it means that text was #define'd somewhere.
ok, but i thought i was using a class and all that to prevent having to reference stuff in parameters though. is there a way to do it without putting int seven in void CLASS::Function2() ??

I didnt know about the all caps thing, i'll try to use lowercase.
Last edited on
i thought i was using a class and all that to prevent having to reference stuff in parameters

That true if your class has storage items, however, your class does not.

Since seven is a constant, you could declare it within the class, but you would have to initialize it in a constructor for the class.

1
2
3
4
5
class CLASS
{  int seven;
public:
  CLASS () 
  {seven = 7; }
ok, now what if i wanted to have the user input a number and save it in the seven integer in the class? is that possible or no?
Of course, you'd just have to pass it as an argument to the constructor and have the constructor make sure to set it for you.
How would i do that? can you show me or at least give me a link to a site that has a example of it.
Topic archived. No new replies allowed.