Multiple constructors not working

New to C++, not to programming. Everything appears to be working except the constructor with no parameters. When I try to instantiate Dog using it, I get these errors:

[Error] request for member 'printinfo' in 'dog3', which is of non-class type 'Dog()'

[Error] request for member 'bark' in 'dog3', which is of non-class type 'Dog()'

Surely its something simple, but I can't figure out what it is for the life of me...

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;

class Dog{
public:

	Dog(int x, string y);
	Dog();
	
	void printinfo();
	void bark();
	
	int age;
	string name; 
	
};

Dog::Dog(int x, string y){
	age = x;
	name = y;
	cout << "In constructor: name " << name << " and age " << age << endl;
}

Dog::Dog(){
	cout << "Enter dog's age: ";
	cin >> age;
	
	cout << endl;
	
	cout << "Enter dog's name: ";
	cin >> name;
	
	cout << endl;
	
	cout << "Dog's age is " << age << ", dog's name is " << name << endl;
}

void Dog::printinfo(){
	cout << "Printing info for " << name << ", age " << age << endl;
}

void Dog::bark(){
	if(age >= 5){
		cout << name << " is barking. Bark. Bark. Bark." << endl; 
	}
	else{
		cout << name << " is barking. Bark." << endl; 
	}
}

int main(){
	cout << endl;
	
	Dog dog1(14, "Lucy");
	Dog dog2(4, "Cocoa");
	Dog dog3();
	
	dog1.printinfo();
	dog2.printinfo();
	dog3.printinfo();
	
	dog1.bark();
	dog2.bark();
	dog3.bark();
	
	cout<<endl;
}
Line 56 prototypes a function that takes no parameters and returns a Dog. Either omit the parentheses (they do nothing), or replace them with curly braces.
1
2
// Dog dog3() ; // 'dog3' is a function.
Dog dog3 ; // 'dog3' is an object. 

See: https://en.wikipedia.org/wiki/Most_vexing_parse
Ah, thanks. I'm used to java, where you include the brackets when instantiating an object no matter what.
Topic archived. No new replies allowed.