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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:14:15+00:00 2026-05-11T05:14:15+00:00

I am not sure whether I am missing something basic. But I am unable

  • 0

I am not sure whether I am missing something basic. But I am unable to understand why the compiler is generating the error for this code:

class A { };  class B { public:     B();     A* get() const;  private:     A* m_p; };  B::B() {     m_p = new A; }  A* B::get() const {     //This is compiling fine     return m_p; }  class C { public:     A* get() const; private:     A m_a; };  A* C::get() const {    //Compiler generates an error for this. Why?      return &m_a; } 

EDIT: The compiler error is : error C2440: ‘return’ : cannot convert from ‘const class A *’ to ‘class A *’ Conversion loses qualifiers

  • 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. 2026-05-11T05:14:16+00:00Added an answer on May 11, 2026 at 5:14 am

    const in the function signature tells the compiler that the object’s members may not be modified. Yet you return a non-const pointer to a member, thus allowing a violation of that promise.

    In your class B, you make/break no promise since you don’t return a pointer to a member, you return a copy of it (and the member happens to be a pointer).

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

Sidebar

Ask A Question

Stats

  • Questions 532k
  • Answers 532k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, you’re right: Using a singlebyte string function on a… May 17, 2026 at 12:04 am
  • Editorial Team
    Editorial Team added an answer The only way to do this is to ensure that… May 17, 2026 at 12:04 am
  • Editorial Team
    Editorial Team added an answer Below are some simple links to calling __doPostBack http://www.dotnetspider.com/resources/1521-How-call-Postback-from-Javascript.aspx http://wiki.asp.net/page.aspx/1082/dopostback-function/… May 17, 2026 at 12:04 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Not sure whether I am missing something. When making an actor remote, the main
I'm not sure whether it belongs to Stack Overflow, however it's definitely programming-related. I
I'm trying to make a simple xml-editor for some basic but specific needs, the
I need to replace a dynamic substring withing a larger string, but only once
Been working on this problem of collision detection and there appears to be 3
I've been studying my fundamental data structures a bunch recently, trying to make sure
I am working on a project to create a generic equation solver... envision this
For the sake of simplicity, let's assume I'm cloning twitter (I'm not). So every
I try new table structure for our new eccomemrce website like Wordpress tables. But
I have one big php application running on php 4 but I want to

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.