user2952487 user2952487 - 2 months ago 15
C++ Question

shared-ptr and error C4430: missing type specifier - int assumed - C++

Compiler has pointed ,among other mistakes, at strings(emphasized). Have i used the shared_ptr s' wrong? Is compiler able to get in private with purpose of setting the value, by this non-explicit way?

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;
}

Answer

Your header file needs to look like this:

#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();
};