I am a complete beginner to c++. I am learning c++ through the object oriented programming Data structures in c++. In the course I have the following program
Cube.h
#pragma once
class Cube {
public:
double getVolume();
double getSurfaceArea();
void setLength(double length);
private:
double length_;
};
Cube.cpp
#include "Cube.h"
double Cube::getVolume() {
return length_ * length_ * length_;
}
double Cube::getSurfaceArea() {
return 6 * length_ * length_;
}
void Cube::setLength(double length) {
length_ = length;
}
main.cpp
#include <iostream>
#include "Cube.h"
int main() {
Cube c;
c.setLength(3.48);
double volume = c.getVolume();
std::cout << "Volume" << volume << std::endl;
return 0;
}
When I make this program with make main
, I get the following error message
c++ main.cpp -o main
Undefined symbols for architecture x86_64:
"Cube::getVolume()", referenced from:
_main in main-6c5fe0.o
"Cube::setLength(double)", referenced from:
_main in main-6c5fe0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
Not sure what I am doing wrong. I am working from a macbook. I followed this link to run cpp programs in mac.
Not sure what I am doing wrong. An explanation to the error will also be nice.
Thanks in advance