I have been getting this error for my project and I can’t figure out why I am getting it. While this is a common error, none of the other posts seem to have the correct solution.
Can’t figure out this error:
I can’t run this program
[Vector.cpp]
#include <iostream>
using namespace std;
Vector::Vector(int n, int t)
{
this->n = n;
this->p = new int[this->n];
for (int i = 0; i < this -> n;++i)
*(this->p + i) = t;
// this->p[i] = t;
// *((*this).p + i) = t;
}
Vector::~Vector()
{
delete[] this->p;
}
void Vector::Show()
{
for (int i = 0; i < this->n; ++i)
cout << *(this->p + i) << " ";
cout << 'n';
}```
[Vector.h]
```class Vector
{
private:
int n;
int *p;
public:
Vector(int = 3, int = 1);
~Vector();
void Show();
};```
[Here is the terminal error]:
undefined reference to `Vector::Vector(int, int)'
undefined reference to `Vector::Vector(int, int)'
undefined reference to `Vector::Show()'
undefined reference to `Vector::Show()'
undefined reference to `Vector::~Vector()'
undefined reference to `Vector::~Vector()'
I put all file in 1 folder but can't run.
New contributor
Patiny is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.