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

2 Answers 2

6
Material<float> currentMaterial();

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

Material<float> currentMaterial;
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.