user5348754
user5348754

Reputation:

c++ accessing header file information

I am trying to access a variables that I declared in the header file. When I try to assign a variable like women to 0, I receive an error that says "'women' was not declared in this scope." I'm not sure what this means. Do I have to declare the variable in the .cc file again even though it includes school.h? Also, I am receiving an error for my overloaded assignment operators that reads "ISO C++ forbids declaration of ‘School’ with no type, expected ‘,’ or ‘...’ before ‘&’ token, ‘bool operator==(int)’ must have an argument of class or enumerated type."

school.cc

#include "school.h"

void School ()
{
  women = 0;
  rateAI = 0;
  rateSys = 0;
  rateTheory = 0;
  effectiveness = 0;
  ratePubs = 0;
  overallRating = 0;
}

void School (string myName, string myState, int theWomen, int myRateAI, int myRateSys,int myRateTheory, int myEffectiveness, int myRatePubs)
{
  name = myName;
  state = myState;
  women = theWomen;
  rateAI = myRateAI;
  rateSys = myRateSys;
  rateTheory = myRateTheory;
  effectiveness = myEffectiveness;
  ratePubs = myRatePubs;
  overallRating = 0;


bool operator ==(const School &x, const School &y)
{
  return x.overallRating == y.overallRating;
}
bool operator >(const School &x, const School &y)
{
  return x.overallRating > y.overallRating;
}
bool operator <(const School &x, const School &y)
{
  x.overallRating < y.overallRating;
}
bool operator >=(const School &x, const School &y)
{
  x.overallRating >= y.overallRating;
}
bool operator <=(const School &x,const School &y)
{
  x.overallRating <= y.overallRating;
}
bool operator !=(const School &x, const School &y)
{
  x.overallRating != y.overallRating;
}

school.h

#include <string>
#include <iostream>
using namespace std;
#ifndef SCHOOL_H
#define SCHOOL_H
class School {
public:
string name;      
string state;    
int women;      
int rateAI;     
int rateSys;      
int rateTheory;  
int effectiveness;  
int ratePubs;     
int overallRating;  // overall rating that considers all of the above factors 
School ();
School (string myName, string myState, int theWomen, int myRateAI, int myRateSys,
    int myRateTheory, int myEffectiveness, int myRatePubs);
void printSchoolInfo ();
void computeRating (int weightWomen, int weightAI, int weightSys, 
            int weightTheory, int weightEffect, int    weightPubs);
};

bool operator ==(const School &x,const School &y);
bool operator >(const School &x,const School &y);
bool operator <(const School &x,const School &y);
bool operator >=(const School &x,const School &y);
bool operator <=(const School &x,const School &y);
bool operator !=(const School &x,const School &y);
#endif

Upvotes: 0

Views: 47

Answers (1)

Captain Giraffe
Captain Giraffe

Reputation: 14705

Members are defined with the form ClassName::member name.

void School () is a free function. 
School::School(){ is the definition of the constructor. 

The same applies to your other members. Not your free operators.

Upvotes: 1

Related Questions