相同的声明两种不同的类型 [英] Same declaration two different types

查看:87
本文介绍了相同的声明两种不同的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够做到这一点:

I would like to be able to do this:

X<int> type_0;
X<int> type_1; 

,我希望type_0和type_1是两种不同的类型.我该怎么办?

and I would like for type_0 and type_1 to be two different types. How can I do it?

推荐答案

template < typename T, int I > class X; 

X<int, __LINE__ > x0; 
X<int, __LINE__ > x1;

x0和x1将是不同的类型,如果它们不在文件的同一行中,则其他类似的声明也将是不同的类型.

x0 and x1 will be different types as will any other declarations like this if they are not on the same line in the file.

这篇关于相同的声明两种不同的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆