小编Jör*_*gen的帖子

在不同类中实现的纯虚函数的继承

我正在尝试将ac#项目转换为c ++.我正在尝试以下方法:

class IDocInterface
{
 public:
      // implemented in CSpecificDoc
      virtual bool CreateDoc() = 0;

      // implemented in COperations
      virtual void AddOperation() = 0;

      // implemented in CDoc
      virtual void Save() = 0;
};

class COperations
{
 public:
      void AddOperation() {}; // implementation for CDoc and derivates
};

class CDoc : public IDocInterface, public COperations
{
    public:
         void Save() {}; // implemented here
};

class CSpecificDoc : public CDoc
{
public:
      bool CreateDoc() {}; // implemented here
};
Run Code Online (Sandbox Code Playgroud)

当我尝试做的时候:

  IDoc …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance

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

How do I understand how std::make_shared works?

I came across an elegant line of reading a binary file into a vector like this (that works):

        std::ifstream ifs("myfile.bin", std::ios::binary);
        std::vector<char> buffer(std::istreambuf_iterator<char>(ifs), {});
Run Code Online (Sandbox Code Playgroud)

Instead since I want my vector to be a shared pointer I write:

        std::ifstream ifs("myfile.bin", std::ios::binary);
        auto sp = std::make_shared<std::vector<char>>(std::istreambuf_iterator<char>(ifs), {});
Run Code Online (Sandbox Code Playgroud)

I.e just pass the vector constructor arguments to make_shared (as I usually do to create any shared pointer of any objects). But I get: error: no matching function for call to 'make_shared'?

Detailed output:

/usr/include/c++/11.1.0/bits/shared_ptr.h|873 …

c++ shared

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

标签 统计

c++ ×2

inheritance ×1

shared ×1