I am a beginner in C++ and particularly data structures. This project we are working with truncated series (something like that). I get this weird compilation error and I am not sure what it is telling me. The program was running fine before I created the copy constructor so that might be the culprit. I was having a hard time making one, but I am not sure if that is how I am supposed to.
The error looks sorta like this:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ostream:1077:1: note:
candidate template ignored: could not match
'basic_string<type-parameter-0-0, type-parameter-0-1, type-parameter-0-2>'
against 'Series'
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ostream:1094:1: note:
candidate template ignored: could not match
'shared_ptr<type-parameter-0-2>' against 'Series'
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ostream:1101:1: note:
candidate template ignored: could not match 'bitset<_Size>' against
'Series'
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
The code:
#include <iostream>
#include <vector>
using namespace std;
class Series {
private:
size_t degree;
vector <double> coefs;
public:
Series():degree(0){ }
Series(size_t d): degree(d){
for(int i = 0; i < (degree+1); i++){
coefs.push_back(0.0);
}
}
Series(double term){
coefs[0] = term;
}
Series(size_t d2,vector <double> newcoeffs): Series(d2) {
for (int i = 1; i < (d2+1); i++) {
coefs.at(i) = newcoeffs.at(i-1);
}
}
Series(const Series & rhs) {
degree = rhs.degree;
vector <double> coefs;
for (int i = 1; i < (degree+1); i++) {
coefs.at(i) = rhs.coefs.at(i);
}
}
~Series() {
coefs.clear();
}
void print(ostream & out) const{
if (degree == 0) {
return;
}
for (int i = 1; i < degree+1; i++)
out << coefs[i] << "x^" << i << " + ";
out << coefs[0];
}
};
ostream & operator <<(ostream & out, const Series & s){
s.print(out);
return out;
}
int main(){
vector <double> v {2.1,3.5,6.2};
vector <double> z {1.1,2.3,4.0};
Series two(3,z);
Series one(two);
cout << one << end;
cout << two << endl;
return 0;
}