指向 C++ 中具有未定义访问权限的类型的指针?
Pointer to type with undefined access right in C++?
C++ 有这 3 种类型 o char:
signed char
- 签名字符
unsigned char
- 无符号字符
char
- 未定义有符号或无符号的字符
"Analogically", C++也有3种指针类型吗? :
const int*
- 指向常量的指针 int
int*
- 指向可变 int
的指针
???
- 指向 int
的指针,如果其常量或可变 尚未定义
在 C++ 中代替 ???
有什么用?
C++不支持,"exact type of this type to be defined later in the program";有些类型是最好的 - "implementation is system dependent"。
所以在 C++ 中没有对应的东西。指针,任何指针,要么是 const 要么是非 const。
一个字符不是 "character which have not defined if its signed or unsigned"; c++ 标准 - "type for character representation which can be most efficiently processed on the target system (has the same representation and alignment as either signed char or unsigned char, but is always a distinct type)."。所以 char 总是 NOT undefined 类型之一。
您误认为 const int*
必然是指向 const int
的指针。示例:
int a; // Not const;
int const* p = &a; // Valid
因此,int const volatile*
就是答案。它可以指向任何 cv 限定的 int
.
C++ 有这 3 种类型 o char:
signed char
- 签名字符unsigned char
- 无符号字符char
- 未定义有符号或无符号的字符
"Analogically", C++也有3种指针类型吗? :
const int*
- 指向常量的指针int
int*
- 指向可变int
的指针
???
- 指向int
的指针,如果其常量或可变 尚未定义
在 C++ 中代替 ???
有什么用?
C++不支持,"exact type of this type to be defined later in the program";有些类型是最好的 - "implementation is system dependent"。
所以在 C++ 中没有对应的东西。指针,任何指针,要么是 const 要么是非 const。
一个字符不是 "character which have not defined if its signed or unsigned"; c++ 标准 - "type for character representation which can be most efficiently processed on the target system (has the same representation and alignment as either signed char or unsigned char, but is always a distinct type)."。所以 char 总是 NOT undefined 类型之一。
您误认为 const int*
必然是指向 const int
的指针。示例:
int a; // Not const;
int const* p = &a; // Valid
因此,int const volatile*
就是答案。它可以指向任何 cv 限定的 int
.