If you're using multiple transaction units (multiple .cpp files), then keep int cyferka; in one file, but either put it as externint cyferka; in the other .cpp file.
I didn't say delete all of "int cyferka" - I said change the version IN MAIN to just cyferka. [EDIT: OP has changed their post; makes this comment largely redundant]
Your error is that you had too many different variables all called "cyferka". (Just like Polish seems to have an awful lot of words translating to "number").
Let me do it for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int cyferka;
void liczba()
{
cyferka = 7;
}
int main()
{
cyferka = 11; // NOT int cyferka = 11
liczba();
cout << cyferka << endl;
}
I have a program with structures. There are a lot of assignments in the main function. I want to define these structures and throw the value assignments to the second file. But in the main function, I just want to load these values with the new function. This will simplify the main function, which is big now because of the array assignments of structures.
This first example was simple because I wanted to understand how to split files into several. However, in your example, I would have to make a few hundred lines of code before the main function to set values to variables in functions where the liczba function defines. I just want to throw the definition of this function out.
I write something like this in main funstion, but something is not working here :
You never run the version of ustawPola() that you have in your second .cpp file ... because you declared another local version of it within main().
In int main():
Change void ustawPola();
to just ustawPola();
But I concur with @Ganado: use the argument list of procedures to pass variables if possible, rather than global variables. If you have a lot of them you can always bundle them up in a struct.
Your compiler should tell in which file and (near) which line that error occurred. We need to see your actual code - at least in that vicinity (NOT just that line).
Your error message is one which often arises as a "knock-on" effect on earlier lines - so we need to see the line ascribed the error message and a few before it.
I presume that my last post solved your previous problem. You are now introducing new ones.
...|23|error: expected unqualified-id before ')' token|
...||In function 'int main()':|
...|18|error: expected primary-expression before ')' token|
...|warning: unused variable 'zawodnik' [-Wunused-variable]|
I am not sure if there should be a variable in the Team structure zawodnik[2]; in the file hpp since it is declared in the second file cpp. As is the case with the structure Team.
The problem here is clearly that one structure is contained within the other and it doesn't suit him.