Home how to make this template typedef valid in c++11?
Reply: 0

how to make this template typedef valid in c++11?

user1442
1#
user1442 Published in June 24, 2018, 3:26 am

I have a code clip like this

  map<string, map<string, map<string, float> > >  map_f;
  map<string, map<string, map<string, string> > > map_s;
  map<string, map<string, map<string, double> > > map_d;

And I just want to make this code concisely as this:

myMap<float>   map_f;
myMap<string>  map_s;
myMap<double>  map_d;

So I tried to use template and using to achieve this:

template<type T>
    using myMap = map<string, map<string, map<string, T> > >;

However, I got an error as:

error: expected expression
template<type T>

My question is, how to modify this code and what does this error means?

The code has been shown blow:

#include <string>
#include <map>
using namespace std;

int main()
{
  template<typename T>  
    using myMap = map<string, map<string, map<string, T> > >;
  return 0;
} 

I compile it with on c++ 4.2.1 @ mac osX 10.13.2:

g++ -std=c++11 temp_def_cls.cxx -o main

And I got the error:

temp_def_cls.cxx:7:3: error: expected expression
  template<typename T> 
  ^
1 error generated.
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313197 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO