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;
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.