假设共享库包含以下行:
const char* const arr[] =
{
"one",
"two",
"three"
};
Run Code Online (Sandbox Code Playgroud)
1)应用程序是否可以链接到此库并使用符号"arr"?
2)如果在定义中添加了新元素,二进制兼容性是否会被破坏?
3)如果其中一个字符串文字被更改了怎么样?
4)为什么(不)?
干杯,卢克
请考虑以下文件:
foo.h中
template <typename T>
struct Foo
{
int foo();
};
template <typename T>
int Foo<T>::foo()
{
return 6;
}
Run Code Online (Sandbox Code Playgroud)
foo.c的
#include "Foo.H"
template <>
int Foo<int>::foo()
{
return 7;
}
Run Code Online (Sandbox Code Playgroud)
MAIN.C
#include <iostream>
#include "Foo.H"
using namespace std;
int main()
{
Foo<int> f;
cout << f.foo() << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译并运行时,打印7.这里发生了什么?什么时候模板实例化?如果编译器这样做,编译器如何知道不实例化它自己的Foo版本?