Home > front end >  what functionname().anotherfunctionname() means in C
what functionname().anotherfunctionname() means in C

Time:01-19

for example in C we use:

int a = 12;
typeid(a).name();

to get type of a variable

my question is what exactly typeid is (im nearly sure its a function but Clion shows nothing) and if its a function how it inherites or something the name() function

i tried to get what type id is but Clion showed nothing (when suggestion pops up in Clion for example when u type na it shows the suggestion and it shows and f infront of name so i know its a function but for typeid its empty)

edit: is there a way to make something similar?

CodePudding user response:

According to enter image description here https://en.cppreference.com/w/cpp/types/type_info

CodePudding user response:

The construct does the following: the first function call has a return value of an object, which has the second function name as a member function.

E.g. in a more generic context:

#include <iostream>
struct AnObject
{
  void anotherFunctionName ()
  {
    std::
      cout << "anotherFunctionName() member of AnObject was called" << std::
      endl;
  }
};

AnObject
aFunctionName ()
{
  std::cout << "aFunctionName() was called, returning AnObject" << std::endl;
  return AnObject ();

}

int
main ()
{
  // Return an instance of AnObject, and call its member function:
  aFunctionName ().anotherFunctionName ();
}

CodePudding user response:

typeid is a bit special since it's a keyword, which is likely why you weren't able to find too much information regarding it on CLion. Similarly you won't be able to find much on other keywords like int or if.

Nonetheless, the result of using typeid(some_variable) would be an std::type_info(a perfectly fine class), which would allow you to continue calling member functions like .name().

  • Related