I've created Dynamic library
project Foo
and it has following code in the Foo.h
:
#pragma once
#include <memory>
#ifdef MYLIB_EXPORTS
#define MYLIB_API __declspec(dllexport)
#else
#define MYLIB_API __declspec(dllimport)
#endif
class MYLIB_API Foo
{
};
template class MYLIB_API std::tr1::shared_ptr<Foo>;
typedef std::tr1::shared_ptr<Foo> FooPtr;
I use Foo
class from my ConsoleApplication1
:
#include "stdafx.h"
#include "Foo.h"
template class std::tr1::shared_ptr<Foo>; // (1)
int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
std::tr1::shared_ptr<Foo>(new Foo()); // (2)
return 0;
}
The code above is compiled without error/warnings. I use Visual Studio 2008 (v90)
toolset to compile this. Both projects is compiled with /W4
.
Questions:
1. Why (1) doesn't produce any compiler errors/warnings? I've expected here something like C2011 type redefinition
. I suspect (1) is ignored.
2. How many instantiations of std::tr1::shared_ptr<Foo>
there are? As it is compiled, I've expected that there two instantiation: one in the Foo
and another in the consoleapplication1
.
3. Which instantiation (if there are many) is used at (2)?
UPDATE1:
I compiled this with Assembly With Source Code (/FAs)
, and seems that both Foo
and ConsoleApplication1
contain implementation of shared_ptr<Foo>
. Doesn't this mean that there are two shared_ptr<Foo>
explicit instantiation?