default parameters in constructor?

this code won't compile. it gives a linking error because i'm calling a function that doesn't exist but i thought with the default parameters i should be able to instead of creating a new function that does this:
1
2
3
4
5
point()
{
x=0;
y=0;
}


i've tried ano parameter constructor calling this(0,0) and that doesnt work either have to much java on the brain.

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
28
#include <iostream>
using namespace std;

struct point{
	friend ostream& operator<<(ostream& out, const point &in);
public:
	point (int inputOne=0, int inputTwo=0)
	{
		x=inputOne;
		y=inputTwo;
	}
private:
	int x;
	int y;
};

int main()
{
	point pointOne();
	cout<<pointOne;
	return 0;
}

ostream& operator<<(ostream& out,const point &in)
	{
		out<<"x="<<in.x<<" "<<"y="<<in.y;
		return out;
	}
well, i've found out the problem. its because of
1
2
point pointOne();///doesn't compile
point pointOne;/// will compile 


but why is there a difference?
Google "C++ most vexing parse"

The first line looks to the compiler like you a prototyping a function named "pointOne" which takes no parameters and returns a point.
thanks for the info

Topic archived. No new replies allowed.