Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9255395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:42:29+00:00 2026-06-18T11:42:29+00:00

I am unable to access a member function of one class inside another, though

  • 0

I am unable to access a member function of one class inside another, though I can access it fine in main(). I’ve been trying to switch things around, but am unable to understand what am I doing wrong. Any help would be appreciated.

Here is the line that generates the error:

cout << "\n\nRetrieve key from inside Envelope class: " << e.getData() << "\n\n";

And here is the code:

class Record{
  private:
    string key;
  public:
    Record(){ key = ""; }
    Record(string input){ key = input; }
    string getData(){ return key; }
    Record operator= (string input) { key = input; }
};

template<class recClass>
class Envelope{
  private:
    recClass * data;
    int size;

  public:
    Envelope(int inputSize){
      data = new recClass[inputSize];
      size = 0;
    }
    ~Envelope(){ delete[] data; }
    void insert(const recClass& e){
      data[size] = e;
      cout << "\n\nRetrieve key from inside Envelope class: " << e.getData() << "\n\n";
      ++size;
    }
    string getRecordData(int index){ return data[index].getData(); }
};

int main(){

  Record newRecord("test");
  cout << "\n\nRetrieve key directly from Record class: " << newRecord.getData() << "\n\n";

  Envelope<Record> * newEnvelope = new Envelope<Record>(5);
  newEnvelope->insert(newRecord);
  cout << "\n\nRetrieve key through Envelope class: " << newEnvelope->getRecordData(0) << "\n\n";

  delete newEnvelope;
  cout << "\n\n";
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:42:31+00:00Added an answer on June 18, 2026 at 11:42 am

    You are passing e as a constant reference void insert(const recClass& e){
    And then you are calling a method (getData()) not declared as constant.

    You can fix it by rewriting getData() like this:

    string getData() const{ return key; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Error accessing structure member inside using member function of class. Hello i am unable
I'm unable to figure out how to use the memoize function inside a class.
Im unable to access server/response variable in my static function. Can i access them
When trying to access the database, I am unable to access the column. I
I have a @property listOfSites declared in a class. I am unable to access
I have a method inside of a MooTools class that I want to access
Newbie question on drools. I am trying to access the following java class in
http://jsbin.com/ifoguf/19/edit I'm unable to access the get area function of Triangle, and getting a
I have one main class main, which I use to store the configuration and
I try to access the MainContentBlock control from the aspx, but unable to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.