Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第六章 类型转换小错误 #24

Open
Exiaozhang opened this issue Oct 29, 2024 · 3 comments
Open

第六章 类型转换小错误 #24

Exiaozhang opened this issue Oct 29, 2024 · 3 comments

Comments

@Exiaozhang
Copy link

类型转换回顾中C++应该是强类型语言
image

@guyutongxue
Copy link
Owner

这里符合语义。弱类型是指允许隐式类型转换的语言,强类型是指不允许隐式类型转换的语言。

国内部分教科书喜欢将“静态类型”定义为“强类型”而将“动态类型”定义为“弱类型”,这其实是不太符合学界的定义的。

@Exiaozhang
Copy link
Author

image
第七章的指针“隐式转换”这里的代码编译不通过,是不是指的这个意思


class Base {};
class Derived : public Base {};
void f(Base *);

int main() {
  Derived d;
  Derived *ptrd{&d};
  Base *b{&d}; // 从 Derived* 类型隐式转换到 Base* 类型
  b = ptrd;    // 同上
  f(ptrd);     // 同上
}

@guyutongxue
Copy link
Owner

第七章的指针“隐式转换”这里的代码编译不通过,是不是指的这个意思

是少了一个 &,稍后修正

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants