小编The*_*oid的帖子

什么是迭代器的默认值?

对于我正在使用的任何STL容器,如果我使用迭代器的默认构造函数声明一个迭代器(此特定容器类型),迭代器将初始化为什么?

例如,我有:

std::list<void*> address_list;
std::list<void*>::iterator iter;
Run Code Online (Sandbox Code Playgroud)

什么会被初始化?

c++ containers iterator stl default

60
推荐指数
3
解决办法
5万
查看次数

调用基类构造函数

在下面的程序中,是行

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)

c++ inheritance derived-class default-constructor

4
推荐指数
1
解决办法
2万
查看次数

关于构造函数的成员初始化列表和抛出的C++语法问题

如何编写既有throw又有成员初始化列表的ctor定义?它是否正确?

ClassName::ClassName(int parameter): datamember_(parameter) throw(ExceptionType)
Run Code Online (Sandbox Code Playgroud)

c++

2
推荐指数
1
解决办法
638
查看次数