• 使用类模板时的一点困惑


     1 #include<string>
     2 #include<iostream>
     3 
     4 using namespace std;
     5 
     6 ///通过嵌套实现元则
     7 template<typename T,typename N>
     8 class my_tuple
     9 {
    10 public:
    11     T value;
    12     N next;
    13     my_tuple(T const &v,N const &n):value(v),next(n){}
    14 };
    15 template<typename T,typename N>
    16 my_tuple<T,N> push(T const &v,N const &n)
    17 {
    18     return my_tuple<T,N>(v,n);
    19 }
    20 int main()
    21 {
    22     typedef my_tuple<int ,char> tuple2;
    23     typedef my_tuple<float,tuple2> tuple3;
    24     typedef my_tuple<std::string,tuple3> tuple4;
    25 
    26     tuple4 tup4 = push(std::string("awesome"),
    27               push(.5f,
    push(2,'a'))); 28 cout<<tup4.value<<"," 29 <<tup4.next.value<","; 30 cout<<tup4.next.next.value<<"," 31 <<tup4.next.next.next<<endl; 32 //此时输出结果为: awesome,0.52,a 33 //奇怪的是逗号少输出了一个 34 //开始我用的输出格式是cout<<tup4.value<<","<<tup4.next.value<","<<tup4.next.next.value<<","<<tup4.next.next.next<<endl; 35 //直接就报错了:test.cpp||error: invalid operands of types 'const char [2]' and 'int' to binary 'operator<<' 36 }

    希望大神们看到了能给出一点提示

  • 相关阅读:
    time和/usr/bin/time
    Linux系统-real/user/sys time
    PL/SQL:集合类型 (定义,分类,使用场景,集合方法)
    关于Android开发中使用的XML
    Android Studio 常用快捷键
    Android中Adapter总结
    Android 中的 Context
    Android Studio 项目结构
    Android Studio 连接真机调试
    Android Studio 入门
  • 原文地址:https://www.cnblogs.com/webary/p/3904897.html
Copyright © 2020-2023  润新知