I'm working on some basic C++ code that uses two cpp files(Main.cpp and CarbStore.cpp) and one header(CarbStore.h). Within my header I have declared a function that is later implemented in CarbStore.cpp. When I call the function from my Main.cpp it gives me the error:
Main.cpp:17: undefined reference to `CarbStore::CalcCarbs(unsigned char, unsigned char, unsigned char, float, unsigned int, std::__cxx11::basic_string, std::allocator >) const'
My files contain the following code:
Main.cpp
#include <iostream>
#include <cstdint>
#include <cmath>
#include <ctime>
#include "CarbStore.h"
void CarbCalculator()
{
CarbStore carb;
carb.CalcCarbs(10, 11, 12, 0.1, 100, "test");
}
int main(int,char *[])
{
CarbCalculator();
std::cout << "Press enter to exit." << std::endl;
std::cin.get();
}
CarbStore.cpp
#include "CarbStore.h"
#include <iostream>
void CalcCarbs(unsigned char r, unsigned char b, unsigned char g, float bounciness, unsigned int price, std::string manufacturer)
{
//use values at later state
return;
}
CarbStore.h
#ifndef CARBSTORE_H
#define CARBSTORE_H
#include <vector>
class CarbStore
{
public:
void CalcCarbs(unsigned char r, unsigned char b, unsigned char g, float bounciness, unsigned int price, std::string manufacturer) const;
};
#endif