I am trying to compile an example program from Malik chapter 10: Election Results and I am getting the error below:
4 0 C:\Dev-Cpp\MalikChapter10\main.cpp In file included from main.cpp
52 20 C:\Dev-Cpp\MalikChapter10\candidateType.h [Error] 'noOfRegions' was not declared in this scope
C:\Dev-Cpp\MalikChapter10\main.cpp In function 'int main()':
32 16 C:\Dev-Cpp\MalikChapter10\main.cpp [Error] 'class orderedArrayListType<candidateType>' has no member named 'selectionSort'
42 15 C:\Dev-Cpp\MalikChapter10\main.cpp [Error] 'printHeading' was not declared in this scope
28 C:\Dev-Cpp\MalikChapter10\Makefile.win recipe for target 'main.o' failed
#ifndef CANDIDATETYPE_H
#define CANDIDATETYPE_H
#include "personType.h"
class candidateType : public personType
{
public:
const candidateType& operator=(const candidateType&) ;
//Overload the assignment operator for the objects of the type candidateType
const candidateType& operator=(const personType&);
//Overload the assignment operator for the object so that the value
//of an object of the type personType can be assigned to an object of the type candidateType
void setVotes(int region, int votes);
//Function to set the votes of a candidate for a particular region.
//Postcondition: The votes specified by the paramenter votes
// are assigned to the region specified by the parameter region
void updateVotesByRegion(int region, int votes);
//Function to update the votes of a candidate for a particular region
//Postcondition: The votes specified by the parameter votes are added to the region
//specified by the parameter region.
void calculateTotalVotes();
//Function to calculate the total votes received by a candidate
//Postcondition: The votes received in each region are added.
int getTotalVotes();
//Function to return the total votes received by a candidate.
//Postcondition: The total votes received by the candidate are returned
void printData() const;
//Function to output the candidate's name, the votes received
//in each region, and the total votes received.
// void printResults(string cNames[],
// int votesByRegion[][noOfRegions],
// int totalVotes[], int noOfRows);
candidateType();
//default constructor
//Postcondition: Initialize the votes received in each region,
// and the total votes received , to zero.
//Overload the relational operators.
booloperator==(const candidateType& right) const;
booloperator!=(const candidateType& right) const;
booloperator<=(const candidateType& right) const;
booloperator<(const candidateType& right) const;
booloperator>=(const candidateType& right) const;
booloperator>(const candidateType& right) const;
private:
int votesByRegion[noOfRegions];
int totalVotes;
};
#endif
First this int votesByRegion[noOfRegions]; is not allowed and does not work. At compile time what is between the [] brackets needs to be a constant number so the compiler can know how much space to set aside for this array. This can be done withconstint NOOFREGIONS{ 5 }; or the newer constexprint NOOFREGIONS{ 5 }; or even #define NOOFREGIONS 5 .
By your error message it looks like "noOfRegions" is not defined anywhere before it is used in the class.