classes error expression must have a class type

I have attached my header and cpp files. I have the problem as listed in the subject line and would very much appreciate some guidance. I have enclosed the problem line in ****. Thank you so much.

#ifndef POPULATION_H
#define POPULATION_H
#include <iostream>
#include <iomanip>

using namespace std;

class Population
{
private:
double birthRate() const;
double deathRate() const;

public:
int births;
int deaths;
int pop;
Population(int pop, int births, int deaths);

int setBirths() //const
{
return births;}

int setDeaths()
{
return deaths;}

int setPop()
{
return pop;}


int getBirths() //const
{
return births;}

int getDeaths()
{
return deaths;}

int getPop()
{
return pop;}

double getBirthRate() const
{ return pop/births;}

double getDeathRate() const
{return (pop/deaths);}

};

#endif

//Implementation file for Population class
#include "population.h"
#include <iostream>
#include <iomanip>
using namespace std;
//population.h 09/20/11

//Population::Population(int p, int b, int d)

int main()

{
Population testPop();

int births;
int deaths;
int pop;



//Get the population
cout << "Enter the population: ";
cin >> pop;

cout << "Enter the number of births: ";
cin >> births;


cout << "Enter the number of deaths: ";
cin >> deaths;

//*******************************************************************
cout << "The birth rate is: " << [testPop.getbirthRate << endl;
//**********************************************************************
system("pause");
return 0;
}

The [ was put there by attempting to bold the area while posting. It is not in the actual code. Thank you.
Corrected case error in getBirthRate. still not working. Please help.
getBirthRate is a function. Call it like one: getBirthRate().

EDIT: Well, it looks like you have bigger problems than that.

Last edited on
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef POPULATION_H
#define POPULATION_H
#include <iostream>
#include <iomanip>

using namespace std;

class Population
{
private:
  double birthRate() const;  // don't need these
  double deathRate() const;

public:
  int births;   // these should be private
  int deaths;
  int pop;
  Population(int pop, int births, int deaths);

  int setBirths() //const
  {
    return births;}

  int setDeaths()
  {
    return deaths;}

  int setPop()
  {
    return pop;}


  int getBirths() //const  // use const on gets, not sets
  {
    return births;}

  int getDeaths()
  {
    return deaths;}

  int getPop()
  {
    return pop;}

  double getBirthRate() const
  { return pop/births;}         // this is doing integral division, cast births to a double to get a floating-point result

  double getDeathRate() const
  {return (pop/deaths);}     // this too

};

#endif

//Implementation file for Population class
#include "population.h"
#include <iostream>
#include <iomanip>
using namespace std;
//population.h 09/20/11

//Population::Population(int p, int b, int d) // this constructor needs defined

int main()

{
  Population testPop();  // the compiler thinks this is a forward declaration because of empty ()'s,
                         // pass 3 arguments like the constructor above - note, this also needs moved down
                         // past the cins...to get the values into the class

  int births;
  int deaths;
  int pop;



  //Get the population
  cout << "Enter the population: ";
  cin >> pop;

  cout << "Enter the number of births: ";
  cin >> births;


  cout << "Enter the number of deaths: ";
  cin >> deaths;

//*******************************************************************
  cout << "The birth rate is: " << [testPop.getbirthRate << endl;  // see my first post
//**********************************************************************
  system("pause");
  return 0;
}


Hope that helps.
Last edited on
Thank you so so much.
Topic archived. No new replies allowed.