Skip to main content
GameDev.net gamedev.net
✓ Solved 🔒 Locked

Templated functions with no arguments

Started by sebight Feb 27 at 12:31 PM 1 replies 450+ views
Original Post
sebight
sebight

Hello, I'm looking at the templated functions tests as a source for my code. I want to achieve something like this: Scene::GetComponent<TransformComponent>()

However, if I understand correctly, I can only get the templated type using the argument, which would mean that I need to provide an empty instance of TransformComponent in the parameter?

void GetComponent(asIScriptGeneric* gen)
{
    auto* engine = // ...
    auto id = gen->GetArgTypeId(0); // this returns 0 :(

    asITypeInfo* typeInfo = engine->GetTypeInfoById(id);
    Log::Info("{}", typeInfo->GetName());

    gen->SetReturnObject(nullptr);
}

Maybe I am misunderstanding, but I simply want to register this: T@ GetComponent<T>() and get the typeinfo of the provided type. Is that possible with how the templated functions are implemented?

Thanks!

Accepted Answer

I solved this a few minutes after posting haha. Turns out this is the way to get the type:

auto id = gen->GetFunction()->GetSubTypeId();

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.