I am trying to create a class with a vector with undefined size as class member. My code:
main.cpp
#include "Polynom.h"
#include <iostream>
#include <vector>
using namespace std;
int main() {
Polynom p {{7,-2,3,0,0,8}};
return 0;
}
Polynom.h
#ifndef INC_0001_POLYNOM_H
#define INC_0001_POLYNOM_H
#include "Polynom.h"
#include <iostream>
#include <vector>
using namespace std;
class Polynom {
private:
vector<int> vec;
public:
Polynom(vector<int> vec);
};
#endif //INC_0001_POLYNOM_H
Polynom.cpp
#include "Polynom.h"
#include <iostream>
#include <vector>
using namespace std;
Polynom::Polynom(vector<int> vec){
this->vec=vec;
}
But whenever i try to run this code i get following error,
main.cpp:7: undefined reference to `Polynom::Polynom(std::vector<int, std::allocator<int> >)'
The code was longer initially but I had way too many errors when i tried to run it. So I tried to run the bare bone...
PS:I am trying to create a class where i have to input for example 7,-2,3,0,0,8 then couts 8x^5+0x^4+0x^3+3x^2+-2x^1+7x^0 (with a method), but it is undefined how many numbers i type in.
Edit: I use CLion and the CMakeList is:
cmake_minimum_required(VERSION 3.7)
project(0001)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
add_executable(0001 ${SOURCE_FILES})
MinGW version 5.0
Bundled CMake 3.7.2
Bundled GDB 7.11.1
What is an undefined reference/unresolved external symbol error and how do I fix it?
Isnt helpful because I am relative new to C++ and on that thread it is writen so complicated that I dont understand anything (and dont even how it related to my problem beside the error message)
And there is another Problem according to the CLion there is a parameter type mismatch (At Polynom p {{7,-2,3,0,0,8}};
). Which means that there should be other problems.
How do i adjust my constructor so it can build a class this way Polynom p {{7,-2,3,0,0,8}};