Can i do something like this?

I know how to refrence variables but i was wondering if i could do this or something like it without a class

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
#include <iostream>
#include <string>

using namespace std;

void Function2();
void Function();

int main()
{
    string words[9][9];
    Function();
}


void Function2::Function()
{
    cout << six + seven << endl;
}

void Function2()
{
    int six = 6;
    int seven = 7;
}
Name of a function is not a class name or namespace name. So this statement is incorrect.

void Function2::Function()
ok, well i guess ill just use refrencing, i am trying that now but im not sure why i am getting errors.

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
#include <iostream>
#include <string>

using namespace std;

void Function2();
void Function(int &six, int &seven);

int main()
{
    //string words[9][9];
    Function(six, seven);
}


void Function(int &six, int &seven)
{
    cout << six + seven << endl;
}

void Function2()
{
    int six = 6;
    int seven = 7;
}



C:\Users\Chay Hawk\Desktop\Array Program\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\Array Program\main.cpp|12|error: 'six' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Array Program\main.cpp|12|error: 'seven' was not declared in this scope|
C:\Users\Chay Hawk\Desktop\Array Program\main.cpp||In function 'void Function2()':|
C:\Users\Chay Hawk\Desktop\Array Program\main.cpp|23|warning: unused variable 'six'|
C:\Users\Chay Hawk\Desktop\Array Program\main.cpp|24|warning: unused variable 'seven'|
||=== Build finished: 2 errors, 2 warnings ===|



what am i doing wrong?
Last edited on
The compiler says clear enough that variables used in the call of function Function are not declared. Why do not you read compiler errors?


Function(six, seven);// ????
Topic archived. No new replies allowed.