I don't know what I'm doing wrong here; I had the same issue recently, but can't remember what I did to fix it. I didn't get anywhere with reducing it to a minimal example, so I'll just show exactly what I have.
material.h
#ifndef MATERIAL_H
#define MATERIAL_H
#include "Colour.h"
namespace Graphics
{
class LightTransportParameters
{
float diffuse_;
float specular_;
void normalizeAndSetReflection(float diffuse, float specular);
public:
float transparency;
LightTransportParameters(float diffuse, float specular, float transparency)
: transparency(transparency)
{ normalizeAndSetReflection(diffuse, specular); }
float diffuse() { return diffuse_; }
float specular() { return specular_; }
};
struct Material
{
LightTransportParameters lightTransportParameters;
float refractiveIndex;
Colour colour;
Material(LightTransportParameters lightTransportParameters, float refractiveIndex, Colour colour)
: lightTransportParameters(lightTransportParameters), refractiveIndex(refractiveIndex), colour(colour)
{}
};
}
#endif
material.cpp
#include "Floating.h"
#include "Material.h"
inline void Graphics::LightTransportParameters::normalizeAndSetReflection(float diffuse, float specular)
{
if (Utility::floatEqual(diffuse + specular, 1.0f))
return;
float k = 1 / (diffuse + specular);
diffuse *= k;
specular *= k;
diffuse_ = diffuse;
specular_ = specular;
}
main.cpp
#include <iostream>
#include "Sphere.h"
int main()
{
using namespace Graphics;
using Maths::Vector3;
Sphere s(Vector3(0, 0, 0), 1.0f, Material(LightTransportParameters(0.5f, 0.5f, 0.0f), 1.0f, Colour(1.0f, 0, 0)));
}
Error:
main.obj : error LNK2019: unresolved external symbol "private: void __thiscall Graphics::LightTransportParameters::normalizeAndSetReflection(float,float)" (?normalizeAndSetReflection@LightTransportParameters@Graphics@@AAEXMM@Z) referenced in function "public: __thiscall Graphics::LightTransportParameters::LightTransportParameters(float,float,float)" (??0LightTransportParameters@Graphics@@QAE@MMM@Z)
Obviously the problem is with the declaration of the inline member function, but I'm clearly missing something obvious!