久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是指向-"內部結構"會員被禁止?

Is Pointer-to- quot; inner structquot; member forbidden?(是指向-quot;內部結構會員被禁止?)
本文介紹了是指向-"內部結構"會員被禁止?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個嵌套結構,我想要一個指向嵌套成員之一的成員指針:

i have a nested struct and i'd like to have a pointer-to-member to one of the nested member:

合法嗎?

struct InnerStruct
{
    bool c;
};
struct MyStruct {
    bool t;
    bool b;
    InnerStruct inner;
}; 

這個:

MyStruct mystruct;
//...
bool MyStruct::* toto = &MyStruct::b;

沒問題,但是:

bool MyStruct::* toto = &MyStruct::inner.c;

不是.有什么想法嗎?

謝謝

這里有一些細節是的,它是 &MyStruct::b 而不是 mystruct::b;代碼來自自定義 RTTI/屬性系統.對于每個指定的類,我們保留一個屬性"數組,包括一個 Ptr-to-member它是這樣使用的:

Here are some details Yes it is &MyStruct::b and not mystruct::b; The code is from a custom RTTI/Property system. For each specified class we keep an array of "Property", including a Ptr-to-member It is used like this:

//somewhere else in code...
( myBaseClassWithCustomRTTIPointer)->* toto = true;

推薦答案

是的,這是被禁止的.您不是第一個提出這個完全合乎邏輯的想法的人.在我看來,這是 C++ 中指向成員的指針規范中明顯的錯誤"/遺漏"之一,但顯然委員會對進一步開發指向成員的指針的規范沒有興趣(就像是大多數低級"語言功能的情況).

Yes, it is forbidden. You are not the first to come up with this perfectly logical idea. In my opinion this is one of the obvious "bugs"/"omissions" in the specification of pointers-to-members in C++, but apparently the committee has no interest in developing the specification of pointers-to-members any further (as is the case with most of the "low-level" language features).

請注意,在語言中實現該功能所需的一切都已經存在.指向成員數據成員的指針與指向直接數據成員的指針沒有任何區別.唯一缺少的是初始化此類指針的語法.然而,委員會顯然對引入這樣的語法不感興趣.

Note that everything necessary to implement the feature in already there, in the language. A pointer to a-data-member-of-a-member is in no way different from a pointer to an immediate data member. The only thing that's missing is the syntax to initialize such a pointer. However, the committee is apparently not interested in introducing such a syntax.

從純形式邏輯的角度來看,這在 C++ 中應該是允許的

From the pure formal logic point of view, this should have been allowed in C++

struct Inner {
  int i;
  int j[10];
};

struct Outer {
  int i;
  int j[10];
  Inner inner;
};

Outer o;
int Outer::*p;

p = &Outer::i; // OK
o.*p = 0; // sets `o.i` to 0

p = &Outer::inner.i; // ERROR, but should have been supported
o.*p = 0; // sets `o.inner.i` to 0

p = &Outer::j[0]; // ERROR, but should have been supported
o.*p = 0; // sets `o.j[0]` to 0
// This could have been used to implement something akin to "array type decay" 
// for member pointers

p = &Outer::j[3]; // ERROR, but should have been supported
o.*p = 0; // sets `o.j[3]` to 0

p = &Outer::inner.j[5]; // ERROR, but should have been supported
o.*p = 0; // sets `o.inner.j[5]` to 0

指針到數據成員的典型實現只不過是成員從封閉對象開頭的字節偏移量.由于所有成員(立即數和成員的成員)最終在內存中按順序排列,因此成員的成員也可以通過特定的偏移值來標識.當我說這個功能的內部工作已經完全實現時,這就是我的意思,所需要的只是初始化語法.

A typical implementation of pointer-to-data-member is nothing more than just an byte-offset of the member from the beginning of the enclosing object. Since all members (immediate and members of members) are ultimately laid out sequentially in memory, members of members can also be identified by a specific offset value. This is what I mean when I say that the inner workings of this feature are already fully implemented, all that is needed is the initialization syntax.

在 C 語言中,此功能由通過標準 offsetof 宏獲得的顯式偏移量來模擬.在 C 中我可以獲得 offsetof(Outer,inner.i)offsetof(Outer, j[2]).不幸的是,此功能并未反映在 C++ 指向數據成員的指針中.

In C language this functionality is emulated by explicit offsets obtained through the standard offsetof macro. And in C I can obtain offsetof(Outer, inner.i) and offsetof(Outer, j[2]). Unfortunately, this capability is not reflected in C++ pointers-to-data-members.

這篇關于是指向-"內部結構"會員被禁止?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 国产一区在线免费观看 | 欧美性猛交xxxx乱大交退制版 | 三级网站免费 | 精品国产欧美一区二区三区成人 | 国产精品久久久久久中文字 | 天堂影院av | 亚洲精品免费看 | 91青青草 | 欧美黑人一区二区三区 | 亚洲视频在线观看一区 | 免费91网站 | 五月婷婷激情综合 | 五月婷婷色综合 | 久久成人毛片 | 动漫av在线| 久久久天堂| 欧美日皮视频 | 夜夜嗨av一区二区三区 | 自拍偷拍综合 | 免费毛片在线 | 国产一区在线观看视频 | 亚洲一区二区免费视频 | 亚洲天天看 | 久久一区二区视频 | 国产一区二区中文字幕 | 亚洲精品视频免费在线观看 | 精品视频久久 | 成人精品视频 | 国产在线黄色 | 青青草91| 色婷婷免费视频 | 欧美黄色一区二区 | 国产欧美精品一区二区色综合 | 久久久xxx | 欧美专区在线 | 日本成人免费 | 中文在线观看免费网站 | 成人在线网 | 一区二区色| 国产黄色在线播放 | 成年人一级片 |