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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:45:55+00:00 2026-06-05T07:45:55+00:00

Problem Solved, thank you all for your help! I’ve run into a problem that

  • 0

Problem Solved, thank you all for your help!


I’ve run into a problem that i can’t seem to figure out.

I am trying to overload the ostream operator as a friend function in order to be able to print out the member data of that object, and i can’t seem to get it to work.

This is what i got so far:

.h file:

Class TestIt:
{
public:
TestIt();
TestIt(int a, b);

friend ostream& operator <<(ostream& outputStream, const TestIt& a);

Private:
int NUMBER1;
int NUMBER2;
};

.cpp file:

ostream& operator <<(ostream& outputStream, const TestIt& a)
{
 outputStream << a.NUMBER1 << " " << a.NUMBER2;

return(outputStream);
}

What i am trying to do is, pass in an object in ostream, then output its member data.
The error that i am receiving is that

“the member TestIt::NUMBER1 declared in TestIt.h is inaccessible.

and same error also exists with my other member data.

Why would that be?

Thank you for your help.


Here’s a whole program that i just wrote, giving me the same error:

TestClass.cpp

#include "TestClass.h"
#include <iostream>

using namespace std;

TestClass::TestClass(int a, int b)
{
    age = a;
    whole = b;
}

int TestClass::GetAge() const
{
    return(age);
}

ostream& operator <<(ostream& outputStream, const TestClass& t1)
{
    t1.whole;
    t1.age;

    return(outputStream);
}

TestClass.h

#ifndef TestClass_H
#define TestClass_H

class TestClass
{

public:
    TestClass(int a, int b);
    int GetAge() const;

    friend ostream& operator <<(ostream& outputStream, const TestClass& t1);

private:
    int whole;
    int age;

#endif
  • 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-05T07:45:57+00:00Added an answer on June 5, 2026 at 7:45 am

    The operator<< that you’ve defined and the operator<< that you’ve friended aren’t the same name. Are you using namespaces?

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

Sidebar

Related Questions

I would really appreciate to get your help on this, as I can't seem
I understand the problem that OSGI solved thanks to this question.... What does OSGi
i have a problem that i can't solve ! (sqlite3, but i think it
(Problem solved now, see answers below) Hello, in my app I am trying to
Problem Solved - See bottom for solution notes I'm trying to build a simple
I have the following problem to solve and I can't seem to be able
This problem has been solved thanks to your suggestions. See the bottom for details.
I'm trying to solve this problem all afternoon but with no luck, hopefully someone
I have a problem that I can't solve... In my Activity, I instantiate a
UPDATE SOLVED - Thank's to @MusiGenesis persistence with this I solved the problem by

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.