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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:19:46+00:00 2026-06-08T20:19:46+00:00

I was studying ns-3 tutorial . I cannot understand the following code snippet: class

  • 0

I was studying ns-3 tutorial. I cannot understand the following code snippet:

class MyObject : public Object
{
public:
  static TypeId GetTypeId (void)
  {
    static TypeId tid = TypeId ("MyObject")
       .SetParent (Object::GetTypeId ())
       .AddConstructor<MyObject> ()
       .AddTraceSource ("MyInteger",
                     "An integer value to trace.",
                      MakeTraceSourceAccessor (&MyObject::m_myInt))
       ;
     return tid;
  }

  MyObject () {}
  TracedValue<int32_t> m_myInt;
};

As I understand, MyObject::m_myInt is an access to non-static class member m_myInt from static method and & takes address of this member. This code is successfully compiled and executed. How can it be possible? What instance of class does the static method use?

  • 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-08T20:19:50+00:00Added an answer on June 8, 2026 at 8:19 pm

    Pointers to members can be pointers to either member methods or member variables and do not need an instance of a class to be declared or assigned. This does not mean you can do much without an instance, however. You still need an instance to use them. Consider the following code:

    class A
    {
    public:
        void SomeMethod();
        int someVar;
    };
    
    void (A::*pSomeMethod)() = &A::SomeMethod; //Declares a member pointer to method and assigns
    int A::*pSomeVar = &A::someVar; //Declares a member pointer to int variable and assigns
    
    A a; //Defines an instance
    (a.*pSomeMethod)(); //Uses an instance with the pSomeMethod member pointer.
    int var = (a.*pSomeVar); //Uses an instance with the pSomeVar member pointer.
    

    It is possible, and it allows for some pretty cool stuff.

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

Sidebar

Related Questions

I'm currently studying this tutorial : and I understand completely how to rotate/scale/translate each
While studying for a Functional Programming exam, I came across the following questions from
While studying for a Functional Programming exam, I came across the following question from
In studying actionscript 3's graphics class, I've come across the undocumented drawRoundRectComplex() method. It's
While studying for the Zend PHP Exam I came across the following contradicting information:
I am studying WPF databinding using this tutorial . Here is my XAML: Window
I'm studying jQuery with this tutorial, but one of examples doesn't work. <html> <head>
I'm studying the use of threading in the Lunar Lander sample code, and I'm
I started studying jQuery yesterday by doing tutorials well I'm on tutorial 28 /200
I've been studying how to use anti-alias in OpenGL. Here is a tutorial I

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.