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

僅用于數據的類與結構?

Class vs Struct for data only?(僅用于數據的類與結構?)
本文介紹了僅用于數據的類與結構?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在這種情況下,使用類比使用結構有什么優勢嗎?(注意:它只會保存變量,永遠不會有函數)

Is there any advantage over using a class over a struct in cases such as these? (note: it will only hold variables, there will never be functions)

class Foo { 
private:   
   struct Pos { int x, y, z };
public:    
   Pos Position; 
};

對比:

struct Foo {
   struct Pos { int x, y, z } Pos;
};

<小時>

類似問題:


Similar questions:

  • 什么時候應該使用類與C++ 中的結構體?
  • struct 和 class 有什么區別C++?
  • 我什么時候應該使用結構而不是班級?

推薦答案

使用一個并沒有真正的優勢,在 C++ 中,結構和類之間的唯一區別是其成員的默認可見性(結構默認為public,類默認為private).

There is no real advantage of using one over the other, in c++, the only difference between a struct and a class is the default visibility of it's members (structs default to public, classes default to private).

就我個人而言,我傾向于將結構用于 POD 類型,而將類用于其他所有類型.

Personally, I tend to prefer structs for POD types and use classes for everything else.

litb 在評論中提出了一個很好的觀點,所以我要在這里引用他:

litb made a good point in the comment so I'm going to quote him here:

另一個重要的區別是結構派生自其他默認情況下,類/結構公共,而類通過私有派生默認.

one important other difference is that structs derive from other classes/struct public by default, while classes derive privately by default.

這篇關于僅用于數據的類與結構?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 亚洲精品一区二区三区在线 | 日韩一二区在线观看 | 亚洲一二三区av | 日日操操 | 国产精品 亚洲一区 | 91精品国产综合久久久久久蜜臀 | 国产精品久久久久免费 | 美女一级a毛片免费观看97 | 欧美1区2区| 欧美久久久久久 | www.97zyz.com| www在线视频 | 国产一二区视频 | 欧美专区在线 | 国产一区二区视频在线观看 | 精品一区国产 | 日p视频免费看 | 亚洲电影一区二区三区 | 视频一区二区中文字幕日韩 | 一区视频| 欧美一区二区三区在线视频 | 婷婷在线视频 | 精品欧美一区二区三区久久久 | 青久草视频 | av大片在线| 一区二区三区中文字幕 | 欧美日韩亚洲视频 | 中文字幕乱码一区二区三区 | 精品免费 | 91视频免费观看 | 精品亚洲永久免费精品 | 国产在线精品一区二区三区 | 中文字幕在线观看一区 | 国产精品99久久久久久动医院 | 可以在线看的黄色网址 | 欧美日韩a| 黄网站免费在线观看 | 精品亚洲第一 | 国产精品一级 | 黄色电影在线免费观看 | 国产欧美一区二区久久性色99 |