samedi 16 janvier 2021

Can I use using instead of typedef when set a pointer to class member variable?

#include <iostream>
using namespace std;

struct Pos {
    int x;
    float y;
};

typedef int Pos::* pointer_to_pos_x;
//using pointer_to_pos_x = ???;

int main()
{
    Pos pos;
    pointer_to_pos_x a = &Pos::x;
    pos.*a = 100;
    cout << pos.x << endl;
}

Can I use using instead of typedef in this situation? I have searched some information on the web. Some people say using can replace typedef, but how can I replace this? Any doc or blog will help.

Aucun commentaire:

Enregistrer un commentaire