3
#include <bits/stdc++.h>
using namespace std;

void union(int x, int y, int link[], int size[])
{
    int a = find(x, link); int b = find(y, link);
    if (size[a] < size[b])
        swap(a,b);
    if ( a != b)
    {
        size[a] += size[b];
        link[b] = link[a];
    }
}


int main()
{
    cout<<"Hello World";

    return 0;
}

I just can't figure out what the hell I am doing wrong. I checked multiple times but to no avail. It's probably something very stupid. It keeps giving the following errors.

file.cpp:19:11: error: expected identifier before '(' token
void union(int x, int y, int link[], int size[])
        ^
file.cpp:19:12: error: expected unqualified-id before 'int'
void union(int x, int y, int link[], int size[])
            ^~~
file.cpp:19:12: error: expected ')'
before 'int'
Anant
  • 302
  • 2
  • 11
  • 5
    `#include ` and `using namespace std;` is a fairly toxic combination, because (a) it is non-portable, and (b) it pulls the entire C++ runtime library into the global namespace, risking further collisions. – Paul Sanders May 08 '20 at 23:08

1 Answers1

7

union is a reserved keyword in C++, and so, you cant use it for a function name. Rename it to something else, for example union_. That will solve your problem.

Azam Bham
  • 1,389
  • 5
  • 6