小编use*_*719的帖子

UNIX'ls'命令排除通配符

我有文件a1 a2 a3 b1 b2 b3,我需要使用ls命令从列表中排除a2和b2 .

unix ls

11
推荐指数
2
解决办法
3万
查看次数

我可以像父母一样使用继承的类指针吗?

我的两个类:Parent和Child都是相同的(现在)并且具有相同的构造函数.

class Parent{
protected:
  string name;
public:
  Parent(string &n, vector <int> &v) {
  /* read n and v into vars */
};

class Child : public Parent {
public:
  Child(string &n, vector <int> &v) : Parent(n, v) {}
};
vector <int> val;
string nam, numb;
if(val[0] == 0) 
  Child* ptr = new Child(nam, val);
else
  Parent* ptr = new Parent(nam, val);

myMap.insert(Maptype::value_type(numb, ptr) );
Run Code Online (Sandbox Code Playgroud)

将Child*ptr对象作为Parent*ptr对象传递是否合法?我听说他们有相同的指针类型,所以应该没问题.那么为什么我会收到警告:未使用的变量'ptr'警告:未使用的变量'ptr'错误:'ptr'未在此范围内声明?我的程序只适用于Parent类.我觉得我没有继承父权.

c++ inheritance constructor pointers

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

标签 统计

c++ ×1

constructor ×1

inheritance ×1

ls ×1

pointers ×1

unix ×1