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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:09:41+00:00 2026-06-12T02:09:41+00:00

I’m fairly new to C++, and I don’t understand what is triggering this error:

  • 0

I’m fairly new to C++, and I don’t understand what is triggering this error:

/home/---/Documents/C++/---_lab2/lab2c.cpp||In function ‘int main()’:|
Line 9: error: ‘float circle::x1’ is private
Line 58: error: within this context

I know the data member x1 (x2,y1,y2 as well) is private, but I am operating on the object myObj using functions that are members of the class circle, so shouldn’t they still work? Can someone explain to me what’s wrong here?

#include <iostream>
#include <cmath>
#define PI 3.14159

using namespace std;

class circle{

private:
float x1,y1,x2,y2;

protected:

float distance(float x1,float y1,float x2, float y2){
    return sqrt(fabs((x2-x1)*(x2-x1))+fabs((y2-y1)*(y2-y1)));
};

public:

float radius(float x1, float y1, float x2, float y2){
    float rad = distance(x1,y1,x2,y2);
    return rad;
};

float circumference(float rad){
    return 2*PI*rad;
};

float area(float rad){
    return PI*rad*rad;
};

float populate_classobj(float x1main,float x2main,float y1main,float y2main){
x1 = x1main;
x2 = x2main;
y1 = y1main;
y2 = y2main;
};

};

int main(){

circle myObj;
float x1main,x2main,y1main,y2main;
cout << "Coordinates of center" << endl;
cout << "X: ";
cin >> x1main;
cout << "Y: ";
cin >> y1main;
cout << "Coordinates of point on circle" << endl;
cout << "X: ";
cin >> x2main;
cout << "Y: ";
cin >> y2main;

myObj.populate_classobj(x1main,x2main,y1main,y2main);

cout << "Radius is " << myObj.radius(myObj.x1,myObj.y1,myObj.x2,myObj.y2) << endl;
cout << "Circumference is " << myObj.circumference(myObj.radius(myObj.x1,myObj.y1,myObj.x2,myObj.y2)) << endl;;
cout << "Area is " << myObj.area(myObj.radius(myObj.x1,myObj.y1,myObj.x2,myObj.y2)) << endl;



return 0;
}
  • 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-12T02:09:43+00:00Added an answer on June 12, 2026 at 2:09 am

    You’re attempting to access private members outside the class when you call radius & other methods.

    But your real problem is with the logic. Why do you need to pass parameters to, for example, the radius method of your class:

    float radius(float x1, float y1, float x2, float y2){
        float rad = distance(x1,y1,x2,y2);
        return rad;
    };
    

    The circle is already self-contained, why not just:

    float radius(){
        float rad = distance(x1,y1,x2,y2);
        return rad;
    };
    

    Same with:

    float circumference(){
        return 2*PI*radius();
    };
    
    float area(){
        return PI*radius()*radius();
    };
    

    Also, note that:

    circle myObj;
    

    creates an invalid object. You shouldn’t have to call populate_classobj just to make it valid. Instead, have a proper constructor:

    circle(float x1main,float x2main,float y1main,float y2main) :
    x1(x1main),
    x2(x2main),
    y1(y1main),
    y2(y2main)
    {
    };
    

    and create the object as:

    circle myObj(x1main,x2main,y1main,y2main);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

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.