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

  • Home
  • SEARCH
  • 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 7598673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:28:03+00:00 2026-05-30T22:28:03+00:00

I’m fairly new to C++ programming and I’ve been getting an error that I

  • 0

I’m fairly new to C++ programming and I’ve been getting an error that I can’t seem to figure out. I’ve tried it many different ways and just get variations of the same error. here is the error and my code:

 account.cxx: In member function ‘char* account::get_name() const’:                                                                                                                                                                     
 account.cxx:26: error: invalid conversion from ‘const char*’ to ‘char*’ 

          //File: account.h
 68     class account
 69     {
 70     public:
 71     typedef char* string;
 72     static const size_t MAX_NAME_SIZE = 15;
 73         // CONSTRUCTOR
 74     account (char* i_name, size_t i_acnum, size_t i_hsize);
 75     account (const account& ac);
 76     // DESTRUCTOR
 77     ~account ( );
 78         // MODIFICATION MEMBER FUNCTIONS
 79     void set_name(char* new_name);
 80     void set_account_number(size_t new_acnum);
 81     void set_balance(double new_balance);
 82     void add_history(char* new_history);
 83     // CONSTANT MEMBER FUNCTIONS
 84     char* get_name ( ) const;
 85         size_t get_account_number ( ) const;
 86         double get_balance( ) const;
 87     size_t get_max_history_size( ) const;
 88         size_t get_current_history_size ( ) const;
 89         string* get_history( ) const;
 90         friend ostream& operator <<(ostream& outs, const account& target);
 91     private:
 92     char name[MAX_NAME_SIZE+1]; //name of the account holder
 93     size_t ac_number; //account number
 94     double balance; //current account balance
 95     string *history; //Array to store history of transactions
 96     size_t history_size; //Maximum size of transaction history
 97     size_t history_count; //Current size of transaction history
 98     };


 1 // File: account.cxx
 2 // Author: Mike Travis
 3 // Last Modified: Feb, 26, 2012
 4 // Description: implementation of Account class as prescribed by the file account.h
 5 
 6 #include <stdio.h>
 7 #include <iostream>
 8 #include "account.h"
 9 
 10 using namespace std;
 11 //Constructor
 12 
 13 account::account(char* i_name, size_t i_acnum, size_t i_hsize){
 14 string *d_history = NULL;
 15 d_history = new string[i_hsize];
 16 
 17 for(int i = 0; i<MAX_NAME_SIZE +1; i++){
 18     name[i] = i_name[i];
 19 }
 20 ac_number = i_acnum;
 21 history_size = i_hsize;
 22 history_count = 0;
 23 }
 24 
 25 char* account::get_name() const {
 26 return &name;
 27 }

I haven’t yet written the rest of the implementation file since I can’t get around this error.

In line 26 of account.cxx I have tried several variations with no success.

  • 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-05-30T22:28:05+00:00Added an answer on May 30, 2026 at 10:28 pm

    You declare get_name() const, which means that this is a const pointer. By extension, name is also const, and can only be converted to const char*. You should return name, not return &name—&name is a pointer to an array, not an array. Array names are implicitly convertible to element pointers; pointers to arrays are not.

    Apart from that, you need only change the declaration to the following:

    const char* get_name() const;
    

    Or the mutable equivalent:

    char* get_name();
    

    However, if you’re using C++, use C++ features: there is a std::string class for a reason, and it will save you a lot of trouble in the long run over using C-style strings:

    string get_name() const;
    

    You’re already using string for history, after all. Also, you might change string* history to vector<string> history, using the std::vector class from the <vector> header. This will hide the details of memory management involved in adding and removing history items.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.