我的 C++ 函数给出异常错误,关于声明
My C++ function gives unusual error, regarding declaration
#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;
}
我只是不知道我到底做错了什么。我检查了很多次但无济于事。这可能是非常愚蠢的事情。它不断给出以下错误。
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'
union
是 C++ 中的保留关键字,因此不能将其用作函数名。将其重命名为其他名称,例如 union_
。那将解决你的问题。
#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;
}
我只是不知道我到底做错了什么。我检查了很多次但无济于事。这可能是非常愚蠢的事情。它不断给出以下错误。
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'
union
是 C++ 中的保留关键字,因此不能将其用作函数名。将其重命名为其他名称,例如 union_
。那将解决你的问题。