mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-10-28 19:04:45 +08:00
- const README: rewrite the space-saving claim per issue #5 follow-ups (constant-expression const vs #define immediates; which const qualify as constant expressions) - const README: fix the class-section diagnosis per issue #338 (overload resolution picks the const overload; the restriction only surfaces once that overload is removed) - sizeof README: virtual-inheritance result is compiler-dependent (GCC merges vbptr+vfptr -> 16, MSVC keeps them separate -> 32) #246 - static README: new section on internal linkage / access restriction with anonymous-namespace comparison #142 - 10-day practice: full problem list table + fixed day links #136 - new design_pattern/singleton/singleton_default.hpp: reusable thread-safe CRTP singleton template, compile+concurrency tested #303
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
# 一文搞懂C和C++中struct
|
||||
> 本文档由 [C++那些事网站](https://light-city.github.io/stories_things/cpp-things/struct/) 同步生成,网站版本含多语言与更新排版。
|
||||
|
||||
# C++ struct 结构体
|
||||
|
||||
## 关于作者:
|
||||
|
||||
个人公众号:
|
||||
|
||||

|
||||

|
||||
|
||||
## 1.C中struct
|
||||
|
||||
@@ -52,7 +54,7 @@ int main() {
|
||||
I am Base func
|
||||
```
|
||||
|
||||
完整代码见:[struct_func.c](./struct_func.c)
|
||||
完整代码见:[struct_func.c](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/struct/struct_func.c)
|
||||
|
||||
## 2.C++中struct
|
||||
|
||||
@@ -135,7 +137,7 @@ int main() {
|
||||
}
|
||||
```
|
||||
|
||||
完整代码见:[struct_func.cpp](struct_func.cpp)
|
||||
完整代码见:[struct_func.cpp](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/struct/struct_func.cpp)
|
||||
|
||||
> 继承案例
|
||||
|
||||
@@ -167,7 +169,7 @@ int main() {
|
||||
}
|
||||
```
|
||||
|
||||
完整代码见:[ext_struct_func.cpp](./ext_struct_func.cpp)
|
||||
完整代码见:[ext_struct_func.cpp](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/struct/ext_struct_func.cpp)
|
||||
|
||||
> 同名函数
|
||||
|
||||
@@ -212,7 +214,7 @@ int main() {
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
完整代码见:[struct_func_func.cpp](./struct_func_func.cpp)
|
||||
完整代码见:[struct_func_func.cpp](https://github.com/Light-City/CPlusPlusThings/tree/master/basic_content/struct/struct_func_func.cpp)
|
||||
|
||||
## 3.总结
|
||||
|
||||
@@ -224,4 +226,4 @@ int main() {
|
||||
| 在C结构体声明中不能使用C++访问修饰符。 | public、protected、private 在C++中可以使用。 |
|
||||
| 在C中定义结构体变量,如果使用了下面定义必须加struct。 | 可以不加struct |
|
||||
| 结构体不能继承(没有这一概念)。 | 可以继承 |
|
||||
| 若结构体的名字与函数名相同,可以正常运行且正常的调用! | 若结构体的名字与函数名相同,使用结构体,只能使用带struct定义! |
|
||||
| 若结构体的名字与函数名相同,可以正常运行且正常的调用! | 若结构体的名字与函数名相同,使用结构体,只能使用带struct定义! |
|
||||
Reference in New Issue
Block a user