I am fairly new to C++. I have started writing a class called Row, and I am trying to call a non-default constructor to create a row object in a separate main.cpp file, but I keep getting an error that I do not understand. Can anyone explain to me what I've done wrong?
Here are my three files:
Row.h
#ifndef ROW_H
#define ROW_H
#include<vector>
#include<iostream>
class Row {
std::vector<int> row;
public:
// constructor
Row(std::vector<int> row);
};
#endif
Row.cpp
#include<vector>
#include<iostream>
#include "Row.h"
// constructor
Row::Row(std::vector<int> row_arg) {
row = row_arg;
}
main.cpp
#include<vector>
#include<iostream>
#include "Row.h"
using namespace std;
int main() {
vector<int> v = {1, 2, 3, 4};
Row row(v);
return 0;
}
The error I receive upon trying to compile main.cpp is this:
/tmp/ccJvGzEW.o:pascal_classes.cpp:(.text+0x71): undefined reference to `Row::Row(std::vector<int, std::allocator<int> >)'
/tmp/ccJvGzEW.o:pascal_classes.cpp:(.text+0x71): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `Row::Row(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status