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

Ex16.49 #199

Open
Coco-Lee opened this issue Jul 18, 2021 · 0 comments
Open

Ex16.49 #199

Coco-Lee opened this issue Jul 18, 2021 · 0 comments

Comments

@Coco-Lee
Copy link

Exercise information

Exercise 16.49
Explain what happens in each of the following calls:

template void f(T); //1
template void f(const T*); //2
template void g(T); //3
template void g(T*); //4
int i = 42, *p = &i;
const int ci = 0, *p2 = &ci;
g(42); g(p); g(ci); g(p2);
f(42); f(p); f(ci); f(p2);

Question or Bug

the answer of

g(ci); // type: const int call template 3 T: const int instantiation: void g(const int)
f(ci); // type: const int call template 1 T: const int instantiation: void f(const int)

should be changed to

g(ci); // type: const int call template 3 T: const int instantiation: void g(int)
f(ci); // type: const int call template 1 T: const int instantiation: void f(int)

becase top-level const is ignored when instantiated.

Your enviroment information

  • System
    N/A
  • Compiler version/IDE
    N/A
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

1 participant