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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:33:09+00:00 2026-05-24T21:33:09+00:00

Simplification of the code to express the concept: class classA { public: private: int

  • 0

Simplification of the code to express the concept:

class classA
{

public:

private:
   int a;
   seta(int x);
};

//local prototype
void somefunction();

int main()
{
  classA object; //create an object of the class

  somefunction(object);
  return 0;
}

void somefunction(classA &object)
{

  object.seta(5);    
}

}

If I move seta() to the public section of the class there is no error and it executes.

However, if I move seta() to the private section, I get the following error:

error C2248:
‘anonymous-namespace'::classA::seta' : cannot access
private member declared in class '
anonymous-namespace’::classA’

If the function is private and only this class is calling it, why is there an issue?

EDIT I am passing the object from main to the local function

  • 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-24T21:33:10+00:00Added an answer on May 24, 2026 at 9:33 pm

    The function that is calling seta() is not part of classA, so this is an error; that’s the very definition of private. If you were to make somefunction() a member of classA, or declare it to be a friend of classA, then this would work.

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

Sidebar

Related Questions

This is my code (simplification of a real-life problem): class Foo { public: void
Best explained with code: long pieceLength = Math.Pow(2,18); //simplification ... public void HashFile(string path)
I have a class: class A { private: ComplexClass member1; public: getMember1(){return member1;}; };
This is the code (just a simplification of a real problem): <?php echo memory_get_usage()
Here is a sample code that I have: void test() { Object1 *obj =
While looking at this code (most of which has been removed for simplification of
I am defining a static factory method with: @XmlType(factoryClass=DummyFactory.class, factoryMethod=createNew) public abstract MyClass() {
Below is a simplification of some code I have for a custom View .
Consider the below: #include <iostream> public ref class TestClass { public: TestClass() { std::cerr
Consider the Employee, Manager, and Assistant classes: public class Emp { public string Name

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.