test_templbasename.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <typeinfo>
4 #include <vector>
5 
6 using namespace std;
7 
8 struct IName {
9  virtual std::string name() const = 0 ;
10  virtual ~IName() {}
11 
12 };
13 
14 template<typename T>
15 struct INameT : public IName {
16  virtual std::string name() const { return typeid(T).name(); }
17  virtual ~INameT() {}
18 };
19 
20 struct A : public INameT<int>, public INameT<float>
21 {
22  virtual ~A() {}
23 };
24 
25 int main()
26 {
27  A a;
28 
29  cerr << a.INameT<int>::name() << endl;
30  cerr << a.INameT<float>::name() << endl;
31 
32  // ambiguous, fails to compile.
33  //cerr << a.name() << endl;
34 
35  INameT<int>* ai = &a;
36  cerr << ai->name() << endl;
37 
38  INameT<float>* af = &a;
39  cerr << af->name() << endl;
40 
41 
42  cerr << "Via bases" << endl;
43  vector<IName*> named{ai,af};
44  for (auto n : named) {
45  cerr << n->name() << endl;
46  }
47 
48  return 0;
49 }
static QCString name
Definition: declinfo.cpp:673
int main()
std::string string
Definition: nybbler.cc:12
STL namespace.
virtual std::string name() const
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
virtual ~IName()
virtual ~A()
#define A
Definition: memgrp.cpp:38
virtual ~INameT()
std::size_t n
Definition: format.h:3399
QTextStream & endl(QTextStream &s)