Ich hätte erwartet das alle Situationen einen Log auswerfen, aber nur zwei der Zugriffe loggen.:
Code: Alles auswählen
	pOB->a = 22; 
	pOB->b = 345;
	pOB->c = 22345;
        pOB->Logtest();//Log access
       (*pOB).a = 3;
       (*pOB)->b = 7; //C access 
Hier das Beispiel:
https://godbolt.org/z/rsvT3v5s6
Code: Alles auswählen
#include <iostream>
#include <cstdio>
using namespace std;
class COperTest
{
public:
	long a,b;
    static long c;
	COperTest()
	{
		a=5;
		b=7;
	}
	COperTest & operator *()
	{
		printf("A access %d\n",__LINE__);
		return *this;
	}
	COperTest * operator->() const
	{
		printf("B access %d\n",__LINE__);
		return  const_cast<COperTest*>(this);
	}
	COperTest * operator->()
	{
		printf("C access %d\n",__LINE__);
		return this;
	}
    void Logtest()
    {
        printf("Log access %d\n",__LINE__);
    }
};
long COperTest::c = 33;
void Test()
{
    printf("Test %d\n",__LINE__); //Test 
	COperTest op;
	COperTest *pOB = &op;
	pOB->a = 22; 
	pOB->b = 345;
	pOB->c = 22345;
    pOB->Logtest();//Log access
    (*pOB).a = 3;
    (*pOB)->b = 7; //C access 
}
int main()
{
    cout<<"Hello World" <<endl;
    Test();
    printf("\n\nReady\n");
    return 0;
}