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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:44:28+00:00 2026-06-07T15:44:28+00:00

Apologies for a question that I assume is extremely basic. I am having trouble

  • 0

Apologies for a question that I assume is extremely basic.

I am having trouble finding out online the difference between the operator :: and . in C++

I have a few years experience with C# and Java, and am familiar with the concept of using . operator for member access.

Could anyone explain when these would be used and what the difference is?

Thanks for your time

  • 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-07T15:44:29+00:00Added an answer on June 7, 2026 at 3:44 pm

    The difference is the first is the scope resolution operator and the second is a member access syntax.

    So, :: (scope resolution) can be used to access something further in a namespace like a nested class, or to access a static function. The . period operator will simply access any visible member of the class instance you’re using it on.

    Some examples:

    class A {
        public:
    
            class B { };
    
            static void foo() {}
            void bar() {}
    };
    
    //Create instance of nested class B.
    A::B myB; 
    
    //Call normal function on instance of A.
    A a;
    a.bar();
    
    //Call the static function on the class (rather than on an instance of the class). 
    A::foo(); 
    

    Note that a static function or data member is one that belongs to the class itself, whether or not you have created any instances of that class. So, if I had a static variable in my class, and crated a thousand instances of that class, there’s only 1 instance of that static variable still. There would be 1000 instances of any other member that wasn’t static though, one per instance of the class.

    One more interesting option for when you come to it 🙂 You’ll also see:

    //Create a pointer to a dynamically allocated A.
    A* a = new A();
    
    //Invoke/call bar through the pointer.
    a->bar();
    
    //Free the memory!!! 
    delete a;
    

    Dynamic memory can be a little more confusing if you haven’t learned it yet, so I won’t go into details. Just wanted you to know that you can access members with { :: or . or -> } 🙂

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

Sidebar

Related Questions

I have what is I believe an extremely basic javascript question that for some
Bit support question. Apologies for that. I have an application linked with GNU readline.
Apologies, this is a tragically simple question that will bore most of you. I
I assume this question is language agnostic, and apologies if it's quite rudimentary, but
I have an odd question. Let's assume I create something using scaffolding. This should
My apologies if this is just another question that gets asked over and over.
Apologies if this question has been asked before. I'm hoping that someone can step
Apologies, this is almost certainly a duplicate of this question but as that one
Before I ask this question I would to apologise because of the fact that
My question consists of multiple points that are inherently related, I apologize for that.

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.