C ++ - accessing global variable objects

I am creating a C ++ project and I would like to create a global custom object. I created a custom Material class.

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 I 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);

      

thank

+3


source to share


2 answers


Material<float> currentMaterial();

      

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



Material<float> currentMaterial;

      

+4


source


The compiler considers Material<float> currentMaterial();

in the form Material<float> currentMaterial(void);

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



So you shud write Material<float> currentMaterial;

instead.

+1


source







All Articles