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 7719161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:20:44+00:00 2026-06-01T03:20:44+00:00

for my data structures class, we are making a data structure that we can

  • 0

for my data structures class, we are making a data structure that we can use to easily store and organize data. I am having an issue with the output function of my tree. The error message that I get is:

AccountDB.cpp: In member function ‘void AccountDB::output(std::ostream&) const’:
AccountDB.cpp:23:21: error: passing ‘const AccountDB’ as ‘this’ argument of ‘void    
AccountDB::output(std::ostream&, const AccountDB::Elem*)’ discards qualifiers [-fpermissive]

I’ve been looking around and my output code looks pretty similar to what other people have done. I have no idea, and I don’t really understand what the error is trying to tell.

Thanks for your help.

Header:

#ifndef ACCOUNTDB_H
#define ACCOUNTDB_H


#include <iostream>

using namespace std;


#include "AccountRecord.h"

class AccountDB {

public:
    AccountDB();
    ~AccountDB();
    void insert( const AccountRecord &v );
    AccountRecord * get( const AccountRecord &v );
    void output( ostream &s ) const;

private:
    struct Elem {
        AccountRecord info;
        Elem *left;
        Elem *right;
    };

Elem *root;

void insert( const AccountRecord &v, Elem *&e );
AccountRecord * get( const AccountRecord &v, Elem *&e );
void output( ostream &s, const Elem *e );

};

ostream &operator << ( ostream &s, const AccountDB &v );

#endif

Source

#include "AccountDB.h"

//default constructor
AccountDB::AccountDB() {
    root = 0;
}

//destructor
AccountDB::~AccountDB() {

}

//public
void AccountDB::insert( const AccountRecord &v ) {
    return insert( v, root );
}

AccountRecord * AccountDB::get( const AccountRecord &v ) {
    return get( v, root );
}

void AccountDB::output( ostream &s ) const {
    output( s, root );
}

//private
void AccountDB::insert( const AccountRecord &v, Elem *&e ) {
    if( e == NULL ) {
        e = new Elem();
        e->info = v;
    }

    else if( v < e->info )
        insert( v, e->left );
    else if( v > e->info )
        insert( v, e->right );
}

AccountRecord * AccountDB::get( const AccountRecord &v, Elem *&e ){
    if( e->info == v )
        return &(e->info);
    else if( v < e->info && e->left != NULL )
        get( v, e->left );
    else if( v > e->info && e->right != NULL )
        get( v, e-> right );
    else
        return NULL;
}

void AccountDB::output( ostream &s, const Elem *e ) {

    if( e != NULL ) {
        output( s, e->left );
        s << e->info << endl;
        output( s, e->right );
    }
}

ostream &operator << ( ostream &s, const AccountDB &v ) {
    v.output( s );
    return s;
}
  • 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-01T03:20:45+00:00Added an answer on June 1, 2026 at 3:20 am

    Your output function is not declared const, so when you call

    output( s, root );
    

    the compiler tells you that you are calling a non-const function from inside a const function.

    There are several ways to deal with this – one is to make output const; the other is to make output static (if you can).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the data structures class that I am currently taking, we have been tasked
Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
I have a data structure that represents C# code like this: class Namespace: string
I'm in a data structures class and we have an assignment that includes creating
I took a data structures class in C++ last year, and consequently implemented all
I have a project for my Data Structures class, which is a file compressor
I'm doing an assignment for my Data Structures class. we were asked to to
So I got this question in data structures class' homework, I'm translating so I
I want to implement in Java a class for handling graph data structures. I
Hi I am making a linked list data structure and within the list I

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.