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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:38:14+00:00 2026-06-14T18:38:14+00:00

The warning is being generated by the ostream & operator<<(ostream &os, A &A0) function.

  • 0

The warning is being generated by the ostream & operator<<(ostream &os, A &A0) function.

Here’s how the class’s defined:

class A
{
    public:
        friend ostream & operator<<(ostream &os, A &A0);
        A& operator=(string strSlot_);
        A& operator+(string strSlot_);
        A& operator+(const A &B);
        A& operator=(const A &B);
        string slotReturn();
        A(string strSlot_);
        A(const A &object);
        void slotChange();
        void sCout();
        ~A();
        A();
    private:
        string strSlot;
        int n;
};


ostream & operator<<(ostream &os, A &A0)
{
    os << "strSlot = \"" << A0.slotReturn() << "\"" << endl;
}

string A::slotReturn()
{
    return strSlot;
}

The question is, what is it supposed to return? *this doesn’t seem to work (because it’s a friend?). (It’s merely a warning, but still, I just want to know.)

Also, why can’t I pass A &A0 as a const (in which case the error is: “passing ‘const A’ as ‘this’ argument of ‘std::string A::slotReturn()’ discards 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. Editorial Team
    Editorial Team
    2026-06-14T18:38:15+00:00Added an answer on June 14, 2026 at 6:38 pm

    You need to return the std::ostream& itself:

    ostream & operator<<(ostream &os, A &A0)
    {
       return  os << "strSlot = \"" << A0.slotReturn() << "\"" << endl;
    }
    

    As an aside, the terminology is slightly off. There is no “friend class”. The std::ostream& operator<< is the friend here. But it doesn’t even need to be a friend, because it just calls a public member function of A. So you can remove the friend declaration.

    You should probably also make slotReturn() a const method:

    string slotReturn() const;
            //            ^ const method
    

    and modify the ostream& operator<< to take a const reference:

    ostream & operator<<(ostream& os, const A& A0) { .... }
    

    This will allow you to print out temporaries:

    std::cout << A("I am a temporary!") << "\n"; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to implement a function with both generics and varargs. public class Question
In the following contrived example, data is given a warning due to it being
Warning: touch() [function.touch]: open_basedir restriction in effect. File() is not within the allowed path(s):
Warning: preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, 'info', to be a valid callback in [...]
Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/happy/public_html/source/imap/fet_mail_from_email_add.php on line 7 can't connect:
I'm having some issues getting phpdoc to run correctly. The docs are being generated
How do I flag a function as being deprecated in an iOS Objective-C header
#include stdafx.h #include <string> #include <map> using namespace std; class NiftyEmailProgram { private: typedef
I have some variables in the class public ref class Form1 that I need
The following error: Warning: oci_execute() [function.oci-execute]: ORA-00911: invalid character in F:\wamp\www\SEarch Engine\test1.php on line

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.