0

I have A txt file which contains data on numerous post-secondary graduates. The records are formatted as follows: year province graduation gender numEmployed numGrads. Here is a part of the file:

2000 AB Bachelor's All 6900 7500
2005 AB Bachelor's All 9300 10000
2015 PE Bachelor's All 440 500
2000 PE College All 728 800
2005 AB Bachelor's Females 5642 6200
2010 AB Bachelor's Females 5369 5900
2015 BC Doctorate Females 188 200
2010 BC Doctorate Males 285 300
2005 CAN Bachelor's Males 33396 36300
2000 CAN College Males 28569 32100

So in the first line 2000 is a year, AB is a province, and Bachelor's is the graduation variable

In my ReportGenerator class, I am trying to declare a partial collection organized by year, one organized by province, and one organized by graduation/degree. Each partial collection is supposed to be defined as a collection of Property object pointers, and each Property object stores a collection that is a subset of the records in the primary data collection.

Each element inside these partial collections will hold the records for one specific value of a Property. For ex: one of the properties is year so the ReportGenerator base class will contain a partial collection organized by year, which I called ‘years’ below. The data contains statistics for only four different years (2000, 2005, 2010, and 2015), so the years partial collection will contain exactly four elements, one for each year; the first element of the years collection will contain all the records for the year 2000; the second element will contain those for the year 2005, and so on for the years 2010 and 2015.

year is an integer, and province and graduation are both strings as shown in the Record.cc class. I attempted to declare these 3 partial collections below in my ReportGenerator.h file, but I keep getting the errors:

ReportGenerator.h:25:27: error: template argument 1 is invalid
    static vector<Property*> years; 
                           ^
ReportGenerator.h:25:27: error: template argument 2 is invalid
ReportGenerator.h:26:27: error: template argument 1 is invalid
    static vector<Property*> provinces; 
                           ^
ReportGenerator.h:26:27: error: template argument 2 is invalid
ReportGenerator.h:27:27: error: template argument 1 is invalid
    static vector<Property*> graduation;
                           ^
ReportGenerator.h:27:27: error: template argument 2 is invalid

I basically did the exact same thing for the records collection which is basically just an STL vector of Record pointers, but for some reason it doesn’t give me an error for this vector but it does for the other 3. I would really appreciate some help or a push in the right direction with fixing these errors.

Record.h

#ifndef RECORD_H
#define RECORD_H

#include <iostream>
#include <string>

class Record{
  public:
    Record(int = 0, string = "Unknown", string = "Unknown");
    ~Record();
    
    private:
        int year;
        string province;
        string graduation;
};
#endif

ReportGenerator.h

#ifndef REPORTGENERATOR_H
#define REPORTGENERATOR_H

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;

#include "Record.h"
#include "Property.h"

class ReportGenerator{
  public:
    ReportGenerator();
    static void populate();
  
  protected:
    static vector<Record*> records;
    
    static vector<Property*> years; 
    static vector<Property*> provinces; 
    static vector<Property*> graduation;        
  
};
#endif

Property.h

#include <iostream>
using namespace std;
#include <cstdlib>

template <class T>

class Property{
    public:
         Property& operator+=(const int);
         Property& operator[](int);
    private:
};

I should also mention that Property is a class template, so unlike the other classes there is no Property.cc file. It's just Property.h

Eagerissac
  • 77
  • 7
  • Also please take some time to read [Why is “using namespace std;” considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) Doing it in a header file is *double* the bad practice. – Some programmer dude Dec 04 '20 at 05:41
  • The extra #endif was a typo on this post that was not in the original file, I fixed it sorry about that – Eagerissac Dec 04 '20 at 05:47
  • 2
    `Property` isn't a class, it's a *template*. You need a template-argument for `Property` to become a class, as in `Property`. You can't have a container of templates, only of class instances. – Some programmer dude Dec 04 '20 at 05:54
  • My instructions say to define it as a collection of Property object pointers. So would it be like "static vector Property* years;" or something? I'm a little confused still. – Eagerissac Dec 04 '20 at 06:00
  • Are you sure that `Property` should be a template? Perhaps you should take some time to talk to your teacher or professor? – Some programmer dude Dec 04 '20 at 07:04

1 Answers1

0

I have notice that "Property" is a template class, and "Record" is not.

And you need to declare it completely in ReportGenerator.h


using

static std::vector<Property< TYPENAME >*>

instead of using

static vector<Property*>

And the error compiler complain, i consider that is for std::vector

template argument 1 for element type

template argument 2 for allocator type

Could refer to https://en.cppreference.com/w/cpp/container/vector

NoReason
  • 46
  • 4