| Chris ( Val ) wrote:
|
| > typedef' in themselves do not create any objects,
| > they create 'synonyms' - AKA: A symbolic substitute,
| > also known as an 'alias' for another object.
| >
| > Objects are instantiated later down the track:
| >
| > This:
| > typedef vector<std::string> vNames;
|
| In the special case of a template, typedef-ing also instantiates the target
| class,
Are you sure about that ?
I have not heard of a typedef being responsible
for the actual instantiation of any object(s) ?
| meaning certain lookup paths from inside the template to external
| identifiers get nailed down. By contrast...
I'm not sure what you mean by that.
Can you please elaborate a little further ?
| #define vNames vector<std::string>
|
| would reinstantiate the template each time vNames is used.
Are you certain of this ?
Hmn..., maybe I'm misunderstanding what you mean ?
| I suspect that can introduce subtle bugs.
Ok, here are a couple of tests - Please feel free to
correct me where ever I have erred:
# include <iostream>
# include <ostream>
# include <vector>
namespace Std
{
template<class T> struct MyString
{
MyString() { std::cout << "Ctor-1 MyString\n"; }
MyString( T ) { std::cout << "Ctor-2 MyString\n"; }
MyString( const MyString& )
{ std::cout << "Copy-Ctor MyString\n"; }
};
}
int main()
{
#define vNames std::vector<Std::MyString<int> >
typedef std::vector<Std::MyString<int> > VecMyStr;
VecMyStr V1;
//V1.push_back( Std::MyString<int>() );
//V1.push_back( Std::MyString<int>( 5 ) );
vNames V2;
//V2.push_back( Std::MyString<int>() );
//V2.push_back( Std::MyString<int>( 10 ) );
return 0;
}
In both cases, no objects are constructed until the
'push_back()' member of std::vector is invoked. You
can also verify that the vector size is zero in each
test case.
Can you please explain via an example, exactly what
you were trying to convey if not the above ?
Cheers,
Chris Val