shared-ptr和错误C4430:缺少类型说明符 - 假设int - C ++

时间:2016-09-25 08:39:09

标签: c++ shared-ptr

编译器在其他错误中指出了字符串(强调)。我使用过 shared_ptr s'错误?编译器是否能够以非显式方式设置值来进入私有

stack_class.h

#pragma once  //(i've tried also without this)
#include <memory>
class Stack
{
private:
    shared_ptr<int> n; // this string 
public:
        Stack();
};

stack_class.cpp

//#include's
using namespace std;
Stack::Stack()
{
    shared_ptr<int> n_user(new int);
    cin >> *n_user;
    shared_ptr<int> n(new int);
    this->n = n_user;
}

1 个答案:

答案 0 :(得分:3)

您的头文件需要如下所示:

#pragma once
#include <memory> // ADDED
class Stack
{
private:
    std::shared_ptr<int> n; // ADDED std:: 
    int *s_array;
    std::shared_ptr<int> amount; // ADDED std::
public:
    Stack();
    void Push(int value);
    int Get(int receiver);
    ~Stack();
};