Reputation: 439
You are given a variable p defined in C++ program. Is it possible to find out if it's a pointer to something or a normal variable? specifically, suppose there is a class Test
class Test
{
public:
int test1(int i)
{
}
static int test2(int i)
{
}
const int test3(int i)
{
}
}
Upvotes: 0
Views: 97
Reputation: 234635
You can use, having written #include<type_traits>
std::is_const<decltype(this)>::value
within a member function. If that member function is const
then this value will be true
, else it will be false
.
Note there is no this
in a static
member function, and that this
is always a pointer type in C++.
Upvotes: 1