Learning But I Get Funky Error

Why do I get this error

Error 1 error C3867: 'std::basic_istream<_Elem,_Traits>::get': function call missing argument list; use '&std::basic_istream<_Elem,_Traits>::get' to create a pointer to member c:\users\bollocks\documents\visual studio 2012\projects\project3\project3\main.cpp 14 1 Project3


Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  #include "Dog.h"
#include <string>
#include <iostream>

int main()
{
	Dog D(10,"Peter");
	D.HaveBirthday();

	std::cout << "Dog's Name: " << D.GetName << 
		" Is " << D.GetAge << " Years Old" << std::endl;
	
	return 0;
}


Dog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>

class Dog
{
	public:

		Dog(int Age = 0, std::string Name = "");

		int GetAge();
		std::string GetName();
		void HaveBirthday();

	private:

	protected:

		int Age;
		std::string Name;
};


Dog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Dog.h"
#include <string>

Dog::Dog(int iAge, std::string iName)
{
	Age = iAge;
	Name = iName;
}

int Dog::GetAge()
{
	return Age;
}

std::string Dog::GetName()
{
	return Name;
}

void Dog::HaveBirthday()
{
	Age++;
}
It looks like the error message has nothing common with the code you showed. It seems that your project contains one more file that was compiled.

However even the current code contains error. Instead of

1
2
	std::cout << "Dog's Name: " << D.GetName << 
		" Is " << D.GetAge << " Years Old" << std::endl;


must be

1
2
	std::cout << "Dog's Name: " << D.GetName() << 
		" Is " << D.GetAge() << " Years Old" << std::endl;
thanks for got the brackets, I have one more question I have read somewhere that the const key word should be used on protected variables where would I use that key word here?

Thanks

Madaxe
> I have read somewhere that the const key word should be used on protected variables

The const keyword is used to specify that something is immutable - it can't change once it is initialized.
http://www.parashift.com/c++-faq-lite/const-correctness.html


> where would I use that key word here?

If your Dog's name would never be changed after it has been christened in a constructor, you could make that a const. Once it is const, you could also consider making it public.
1
2
3
4
Dog::Dog(int iAge, std::string iName) : Name(iName) // initialize
{
	Age = iAge;
}

Topic archived. No new replies allowed.