Reputation: 3
I'm writing a program for my class which involves using a class inside of a struct. When defining the struct (named polynomial) 'Polynomial does not name a type'. It triggers on the first line of the default constructor:
Polynomial::Polynomial(){
coefs = vector<Fraction>();
}
Specifically the error occurs on the "Polynomial::Polynomial(){" line.
All other examples I've found for this error include using class B
inside class A before class B is declared. The only member of Polynomial is a vector of class Fractions. I have tried forward declaration of class Fractions and vector is included. This is probably a rookie mistake as I am still very new to C++ classes (this being my first one) so any help would be appreciated.
The relevant portion of the polynomial header file is:
// data members
vector<Fraction> coefs;
// methods
Polynomial() = default;
Upvotes: 0
Views: 3082
Reputation: 1248
polynomial.cpp
needs to include it's header:
#include "polynomial.h"
There is no implicit association between the source (.cpp file) and the header (.h) file in C++. You must include the header for the name Polynomial
to be understood.
Upvotes: 3