c++ - 无法使用std::pair and constructors [closed]编译代码

最佳答案

您的代码可能应如下所示:

#include <utility>
#include <ostream>
#include <iostream>

template <typename T1, typename T2>  
class meta {
   std::pair<T1, T2> xy_pair;

public: 
    meta(const T1 & t1, const T2 & t2) : xy_pair(t1, t2) { }
    // note initialization of the whole member xy_pair, not its members
    meta() : xy_pair() { }

    void print() const {
       cout << xy_pair.first << endl; 
       cout << xy_pair.second << endl; 
    }
}; 

int main() {
   meta<int, int> meta_xy;
}

https://stackoverflow.com/questions/25192871/

上一篇:c++ - "expected ';在返回语句之后,有人可以告诉我我的代码有什么问题吗?

下一篇:c++ - g++,如何找到出错的地方?

相关文章:

c++ - 我应该在 cpp 中使用 std::map 之前调用 clear

c++ - 为什么我可以编译有 2 个返回的代码?

c++ - 引用类型转换运算符 : asking for trouble?

模板化类对象的 C++ vector

javascript - 是否存在像 javascript es6 字符串模板文字这样的 Go 字符串模板?

perl - 如何在Perl中为简单的I/O子例程创建单元测试

c++ - 为什么这段代码会显示 "cannot convert ' double' to 'double*' "错误?

c++ - 在模板函数中从 istream 中提取 bool

vba - 下一个没有?

compiler-errors - 如何添加外部软件包并在rust编译器中运行?

相关文章:

swift - 类型 'Category'(aka 'OpaquePointer')的值没有成员 '

java - 为什么此代码段显示编译错误?

c# - 如果其他语句不起作用

c++ - 以下代码段出了什么问题?

c# - 为什么编译器认为Environment.Exit可以返回?

c++ - 长双二维动态数组C++

objective-c - ARC 不允许将 'int' 隐式转换为 'id _Nonnull'

c++ - "expected ';在返回语句之后,有人可以告诉我我的代码有什么问题吗?

ruby-on-rails-3 - 在命名空间模型上使用 factory_girl_rails 和

java - 我的method.add(int)不会将用户输入添加到我的数组中