Skip to content

Ex16.49 #199

@Coco-Lee

Description

@Coco-Lee

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions