C++,为什么我不能把带有参数的类构造函数的定义-初始化列表放在类声明之外
C++, Why can't I put the definition of class constructor with parameters-initialize list outside the class declaration
为什么不能将类构造函数的定义与参数初始化列表放在类声明之外?
typedef unsigned int UINT;
class num_sequence {
public:
typedef vector<UINT>::iterator iterator;
//I cannot put this following part in the cpp file
num_sequence(vector<UINT> & ele,int len=0,int beg=0):_relems(ele),_length(len),_beg_pos(beg)
{
//an abstract class cannot be instanlized
cout<<"build a num_sequence object";
}
virtual ~num_sequence();
num_sequence.h
#include <vector>
typedef unsigned int UINT;
class num_sequence
{
public:
typedef std::vector<UINT>::iterator iterator;
num_sequence(std::vector<UINT> & ele, int len = 0, int beg = 0);
virtual ~num_sequence();
private:
std::vector<UINT> &_relems;
int _length;
int _beg_pos;
};
num_sequence.cpp
#include "num_sequence.h"
#include <iostream>
num_sequence::num_sequence(std::vector<UINT> & ele, int len, int beg)
: _relems(ele), _length(len), _beg_pos(beg)
{
std::cout << "build a num_sequence object";
}
num_sequence::~num_sequence()
{
}
相关文章:
- 复制列表初始化的隐式转换的等级是多少
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 我使用向量来创建类对象列表.初始化向量时如何使用参数调用构造函数?
- C++11 中的混合列表初始化
- 我可以列表初始化 std::vector 并完美转发元素吗?
- 无法在声明时使用初始值设定项列表初始化常量字符*/字符串数组的向量
- C++20 从括号中的值列表初始化聚合,不支持内部数组
- 如何在向量列表初始化时避免对象复制以及如何延长临时的生存期
- 默认参数和空列表初始化
- 如何在列表初始化中放置额外的语句?
- C++列表初始化允许多个用户定义的转换
- 列表初始化是否将原子初始化为零
- 使用可变模板列表初始化数组,并放置new
- 使用整数初始化列表初始化长双精度的向量
- 直接列表初始化的自动规则
- 使用初始化列表初始化unique_ptr的容器,继续
- 如何修复"非聚合无法使用初始值设定项列表初始化" <map>
- 直接列表初始化和复制列表初始化之间的差异
- 为什么我可以在不使用赋值运算符的情况下使用列表初始化普通数组
- C++ - 使用类中的初始值设定项列表初始化动态集