我試圖瞭解使用offsetof()宏觀acessing結構承包商,客人,我就遇到了這個例子How can I access structure fields by name at run time? 這條線: //Set the value of 'a' using pointer arithmetic
*(int *)((char *)structp + offsetf) = 5;
給我麻
// RecursiveBinarySearch.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define N 9
int RecursiveBinarySearch(int A, int low, int high, int x);
int main()
{
如果我使用mutable與const指針這樣的: class Test
{
public:
mutable const int* ptr; // OK
};
它的正常工作。 但是,如果我用這樣的: class Test
{
public:
mutable int * const ptr; // Error
};
錯誤: prog.cpp:6: