undefined reference overloading function

Working with overloaded functions I get the following error (at bottom):
I've been working with it extensively don't understand it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#include<iostream>

struct X
{
	int value = 6;
};

void print(int value);
void print(double value);

int main()
{
	X x;
	print(x.value);
	return 0;
}



7.6_overloaded_fx\Debug/../src/main.cpp:16: undefined reference to `print(int)'r
Last edited on
You haven't defined print so it doesn't know what to do with the function.

You need to supply a definition. such as:

1
2
3
4
void print(int value)
{
   std::cout << value << std::endl;
}

got it, thx

Below is a simple program to demonstrate some overloading fx's I've learned so far. The cool thing JLBorges showed was the ability to toggle decimal points on and off via showpoint/noshowpoint.

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

struct X
{
	int value = 6;
};

void print(int value)
{
	std::cout<<"Print(Int) Matched with print(int) : "<<value<<std::endl;
}
void print(double value)
{
	std::cout<< std::showpoint ;
	std::cout<<"Print(Double) Value Matched With print(double) caller : "<<value<<std::endl;
	std::cout<<std::noshowpoint;
}

int main()
{
	X x;
	print(x.value);
	print(4.00);
	print(9);
	return 0;
}


output


Print(Int) Matched with print(x.value) : 6
Print(Double) Value Matched With print(double) caller : 4.00000
Print(Int) Matched with print(int) : 9

Last edited on
Topic archived. No new replies allowed.