Undefined reference error for a while compiling

when the linker is trying to link the function call with its definition, it finds the problem and issues the error as “undefined reference”.

#include <iostream>
using namespace std;
int func1();
int main()
{

func1();
}
int func1(int n){
cout<<"hello, world!!";
}
Output:

Wrong definition(signatures don’t match) of objects used, Can somebody please help me solve this? i am literally tried to fix it and it's output is not as i have expected.

Thanks & Regards,
https://myloweslife.xyz/
Last edited on
> int func1();
is not the same as
> int func1(int n)

Make your prototype have an int parameter.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int func1();

int main()
{
    func1();
}

int func1()
{
    cout<<"hello, world!!";
    int some_number = 876;

    return some_number;
}
Last edited on
@OP It's up to you and your design intention whether the function has an integer parameter. Where an integer might be useful as a parameter is in a function something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;

void func1(int);

int main()
{
    func1(3);

}

void func1(int x) // function doesn't return anything
{
    for(int i = 0; i < x; i++)
        cout<<"hello, world!!\n";
}
Topic archived. No new replies allowed.