What are the type requirements for this template function

I am looking at C ++ code that looks like this:

template<class A> bool foo(int A::*) { /*blah*/ } 

What is an int A::* constructor? What requirement does it impose on type A ?

Thanks a lot!

+4
source share
1 answer

int A::* is a pointer to an int data element of type A For example, given the types:

 struct Foo { int i; }; struct Bar { double d; }; 
  • int Foo::* is a pointer to an int data element of type Foo , the only valid values โ€‹โ€‹of which are null and the address Foo::i
  • int Bar::* is a pointer to an int data element of type Bar , the only valid value of which is null, since Bar does not contain int data elements

The only requirement for type A is that it is not a primitive type, since primitive types obviously cannot have data members.

+3
source

Source: https://habr.com/ru/post/1347418/


All Articles