c++ - 'stack::n' : cannot access private member declared in class 'stack' -


class stack {     int n;//problem     char a[100];//problem     int top;    public:     bool isempty()       {         return top == -1;       }          stack()       {             top=-1;       }        bool push(const char &c)       {         if(top == 100)         {             return false;         }          top++;         a[top] = c;          return true;        }        bool pop(char &c)       {         if(top == -1)         {             return false;         }           c = a[top];          top--;       }        char get_top()const       {         return a[top];       }  }; 

c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\code.cpp(73): error c2248: 'stack::n' : cannot access private member declared in class 'stack' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(20) : see declaration of 'stack::n' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(19) : see declaration of 'stack' 1>c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\code.cpp(76): error c2248: 'stack::n' : cannot access private member declared in class 'stack' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(20) : see declaration of 'stack::n' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(19) : see declaration of 'stack' 1>c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\code.cpp(78): error c2248: 'stack::a' : cannot access private member declared in class 'stack' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(21) : see declaration of 'stack::a' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(19) : see declaration of 'stack' 1>c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\code.cpp(79): error c2248: 'stack::a' : cannot access private member declared in class 'stack' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(21) : see declaration of 'stack::a' 1> c:\users\tri\documents\visual studio 2010\projects\assignment01\assignment01\headerfile.h(19) : see declaration of 'stack'

without seeing code.cpp, guesses are:

  1. you're trying access private members outside class. not possible. mark them public, or build public functions class access them.
  2. you may attempting access class members not static. if they're not static, cannot access them stack::. must instantiate object of type stack first, , may access them . accessor applied object.

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -