久久久久久久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?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: av天天澡天天爽天天av | 国产美女精品视频免费观看 | 狠狠视频 | 免费观看黄a一级视频 | 久久精品国产一区 | 99久久久无码国产精品 | 免费视频久久 | 99精品国产一区二区三区 | 久久久久久蜜桃一区二区 | 亚洲自拍偷拍视频 | 成人小视频在线观看 | 中文字幕免费 | 日韩欧美三级 | 做a视频在线观看 | 国内精品久久精品 | 2019天天干夜夜操 | 操人视频在线观看 | 精品成人一区 | 亚洲国产激情 | 国产精品久久久久久亚洲调教 | 久久福利电影 | 国产真实乱对白精彩久久小说 | 乳色吐息在线观看 | 在线欧美 | 精品视频一区二区 | 97国产在线观看 | 午夜资源 | 国产精品福利视频 | 日韩精品一区二区三区中文在线 | 久久99精品久久久久婷婷 | 欧美国产日韩在线观看 | 国产综合精品一区二区三区 | 中文字幕第一页在线 | 日韩一区不卡 | 亚洲欧美中文日韩在线v日本 | 成人三级在线观看 | 午夜精品久久久久久久星辰影院 | 亚洲精品久久久一区二区三区 | 日韩视频在线观看 | 成人免费xxxxx在线视频 | 亚洲男人天堂 |