I have been having a lot of issues with header files, and now it seems that the vector that is declared in my header file, Polynomial.hpp, is not being recognized in Polynomial.cpp. I have already included std:: which seems to be a common mistake, so I don't know where to go from here.
Header file:
#ifndef POLYNOMIAL_HPP #define POLYNOMIAL_HPP #include<vector> #include"term.hpp" class Polynomial { private: std::vector<Term> vect; public: Polynomial(); ~Polynomial(); void add(Term t); void print(); Polynomial combineLikeTerms(); }; #endif cpp File:
#include "term.hpp" #include "Polynomial.hpp" #include<iostream> #include<map> using namespace std; void add(Term t) { vect.push_back(t); } void print() { for(int i = 0; i < vect.size(); i++) { cout << vect[i].toString(); } } Polynomial combineLikeTerms() { Polynomial poly; map<int, int> combinedPoly; for(int j = 0; j < vect.size(); j++) { combinedPoly.insert(pair<int, int>(vect[j].getExponent(), vect[j].getCoefficient()); } for(map<int,int>::iterator itr = combinedPoly.begin(); itr != combinedPoly.end(); itr++) { Term newTerm(itr->second, "x", itr->first); poly.add(newTerm); } return poly; } Error (1/6):
Polynomial.cpp:9:5: error: use of undeclared identifier 'vect' vect.push_back(t);