I am trying to increment a variable of a class with in another during
a recursive call to the main class. I know there are some problems
with the code below, I hope someone would point them out.
thanks
#include <iostream>
#include <string>
#include <vector>
#include <valarray>
#include <sstream>
#include <fstream>
#include <utility>
using namespace std;
class year
{
int yr;
public:
year(int);
void incur_yr();
int get_yr();
};
year::year(int n):yr(n){}
void year::incur_yr(){ yr++;}
int year::get_yr(){ return yr; }
class make
{
string mak;
year yr; // composition
public:
make(string, int);
void incurm_yr();
string get_make();
int get_yr();
};
make::make(string s, int n) : mak(s) { yr(n); }
void make::incurm_yr() { yr.incur_yr; }
string make::get_make(){ return mak; }
int make::get_yr(){ return yr.get_yr; }
int main(){
vector<makecars;
cars.push_back( car("GT", 1970) );
cars.push_back( car("chevy", 1957) );
for(unsigned i=0; i<cars.size(); i++)
for(j=0; j<2; j++)
if(cars[i].get_mak() == GT) {cars[i].incur_yr();}
cout << cars[0].get_yr();
//expected answer is 1772
}