4

I'm building a C++ project and I would like to create a global custom object. I have created a custom class called Material.

rt.h

template<typename T>
class Material
{
    public:
    Vec3<T> ka, kd, ks, kr;
    T sp, transparency, reflectivity;
    Material( ) {
        ka = Vec3<T>(0);
        kd = Vec3<T>(0.0, 0.0, 0.0);
        ks = Vec3<T>(0.0, 0.0, 0.0);
        sp = 0.0;
        kr = Vec3<T>(0.0, 0.0, 0.0);
        reflectivity = 0.0;
        transparency = 0.0;
    }
};

At the top of my rt.cpp file I have the following.

#include <"rt.h">
Material<float> currentMaterial();

Later I call currentMaterial and get an error

raytracer.cpp:294:3: error: base of member reference is a function; perhaps you meant to call it with no arguments?
            currentMaterial.ka = Vec3<float>(kar, kag, kab);

when I call:

currentMaterial.ka = Vec3<float>(kar, kag, kab);

Thanks

Marcus
  • 9,032
  • 11
  • 45
  • 84

2 Answers2

6
Material<float> currentMaterial();

looks like a function declaration to the compiler. Declare your variable like this:

Material<float> currentMaterial;
The Dark
  • 8,453
  • 1
  • 16
  • 19
1

The compiler treats Material<float> currentMaterial(); as Material<float> currentMaterial(void);

A function declaration, with a void argument and a Material return type.

So you shoud write Material<float> currentMaterial; instead.

ljshou
  • 56
  • 1