微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

访问私有成员函数

如何解决访问私有成员函数

美好的一天!在我正在工作的学校项目中, bool isFull() 和 bool isEmpty() 应该是私有的。然而,在提供给我们的代码中, isEmpty 在主程序中被调用。有没有办法让我访问 isEmpty

//data.h
#pragma once

class IntQueue
{
private:
    int *queueArray;
    int queueSize;
    int front;
    int rear;
    int numItems;
  bool isFull();
  bool isEmpty();
public:
    IntQueue(int);
  ~IntQueue();
  void enqueue(int);
  void dequeue(int &);
  void clear();  
};

//main.cpp
while (!iQueue.isEmpty())
    {
        int value;
    try{
        iQueue.dequeue(value);
     }
    catch(const std::invalid_argument) {
    cout << "Exception occurred: Queue Underflow!" << endl;
     }
        cout << value << endl;
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。