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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:42:55+00:00 2026-06-17T22:42:55+00:00

i have two classes (non-static) A & (static) B. I am trying to store

  • 0

i have two classes (non-static) A & (static) B.
I am trying to store Object A into B so that i can use its functions in funcB().
However i do know that static classes cannot store non-static variables & functions. is there anyway to get pass this rather than converting Class A into a static class?

class A
{
   public:
          A();
          void funcA();
   private:
          int A;
};

class B
{
   public:
         B(A *objA);
         static void funcB();
   private:
         A *objA;
};

edit:
I stated static class to make it easier to explain. i did not know the correct term.
So the question is actually: How do i use a non-static member from a static 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-06-17T22:42:56+00:00Added an answer on June 17, 2026 at 10:42 pm

    You can not access anything that is specific to an instance of a class from a static function by itself. A static function has no “this” pointer (the compiler passes a pointer to the instance of the object calling the function for non-static functions). You can get around this by passing a pointer to the object you want to modify, but then why are you using a static function? My advice would be to avoid what it seems like you are trying to do, but I provided 2 ways to do it below (as a good learning example).

    See below for an example of using

        #include <iostream>
    
    using namespace std;
    
    class A
    {
       public:
        A(int value) : a(value){}
              void funcA();
       public:
              int a;
    };
    
    class B
    {
       public:
             B()
             {
                 objA = new A(12);
             }
    
             void funcB2()
             {
                 B::funcB(*objA);
             }
    
             static void funcB(A const & value)
             {
                cout << "Hello World! " << value.a << endl;
             }
    
       private:
             A *objA;
    };
    
    int main()
    {
        A a(10);
        B::funcB(a);
    
        B b;
        b.funcB2();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which I'm trying to accomplish is have two classes, a non generic and a
I'm trying to use two classes' variables as to have access from class A's
I'm trying to use two classes' variables as to have access from class A's
I have a question regarding static members and functions of non static classes. I
I have two classes Foo and Bar that Bar extends Foo as below: class
I have two classes, one that inherits from the other. The base class is
I have two questions about static + const members and static classes. One: Why
I have two classes, Input, and EventSystem. EventSystem is an internal (non-system dependent) class
I have a non-copyable (inherited from boost::noncopyable ) class that I use as a
It seems to me that non-public top-level classes and static nested classes essentially perform

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.