Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Access Global Variables Objects

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

like image 813
Marcus Avatar asked Mar 19 '23 01:03

Marcus


1 Answers

Material<float> currentMaterial();

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

Material<float> currentMaterial;
like image 177
The Dark Avatar answered Mar 28 '23 00:03

The Dark