illegal use of this type as an expression in template

Viewed 73

So I have been working on some kind of small Game Engine and I tried to Add Component system where basically Object has vector of Components and 2 template functions AddComponent and GetComponent. And I get error in GetComponent where I loop through vector of components and if the current components names is equal to typename component name it returns that component. Here is declaration of GetComponent:

template <typename T> Component GetComponent() {

    for (int i = 0; i < components.size(); i++) {

        if (components[i].componentName == T.componentName) {

            return components[i];

        }

    }

    std::cout << "ERROR: GET_COMPONENT_NOT_FOUND_COMPONENT" << std::endl;

}

I have searched at least 5 Stack Overflow articles about this error but no one used it like me. It might be something simple because I don't really understand Templates since I never used them and did just small testing to see how they work.

1 Answers

T::componentName instead of T.componentName.

Related