对于我正在使用的任何STL容器,如果我使用迭代器的默认构造函数声明一个迭代器(此特定容器类型),迭代器将初始化为什么?
例如,我有:
std::list<void*> address_list;
std::list<void*>::iterator iter;
Run Code Online (Sandbox Code Playgroud)
什么会被初始化?
在下面的程序中,是行
Derived(double y): Base(), y_(y)
Run Code Online (Sandbox Code Playgroud)
正确/允许?也就是说,它遵循ANSI规则吗?
#include <iostream>
class Base
{
public:
Base(): x_(0)
{
std::cout << "Base default constructor called" << std::endl;
}
Base(int x): x_(x)
{
std::cout << "Base constructor called with x = " << x << std::endl;
}
void display() const
{
std::cout << x_ << std::endl;
}
protected:
int x_;
};
class Derived: public Base
{
public:
Derived(): Base(1), y_(1.2)
{
std::cout << "Derived default constructor called" << std::endl;
}
Derived(double y): Base(), y_(y)
{ …Run Code Online (Sandbox Code Playgroud) 如何编写既有throw又有成员初始化列表的ctor定义?它是否正确?
ClassName::ClassName(int parameter): datamember_(parameter) throw(ExceptionType)
Run Code Online (Sandbox Code Playgroud)