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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:51:30+00:00 2026-06-09T12:51:30+00:00

I created a class called Kwadrat . The class has three int fields. My

  • 0

I created a class called Kwadrat. The class has three int fields. My Development Environment suggests that I access the fields from Kwadrat created objects via the :: & -> operators. I tried both operators, and found that the -> operator is able to successfully access the data in the objects fields, although, the same cannot be said for the -> operator.
I have also found that the . operator will access class members as well. I am confused, and don’t understand why there are three members for accessing object members &/or methods. Can someone please explain to me what the difference is between the three operators?


          1. ->

          2. ::

          3. .




    #include <iostream>

    using namespace std;

    class Kwadrat{

    public: 
        int val1,
            val2,
            val3;

        Kwadrat(int val1, int val2, int val3)
        {
            this->val1 = val1; // Working
            this.val2 = val2;  // Doesn't Work!
            this::val3 = val3; // Doesn't Work!
        }
    };


    int main()
    {
        Kwadrat* kwadrat = new Kwadrat(1,2,3);

        cout<<kwadrat->val1<<endl;
        cout<<kwadrat->val2<<endl;
        cout<<kwadrat->val3<<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-09T12:51:31+00:00Added an answer on June 9, 2026 at 12:51 pm

    1.-> for accessing object member variables and methods via pointer to object

    Foo *foo = new Foo();
    foo->member_var = 10;
    foo->member_func();
    

    2.. for accessing object member variables and methods via object instance

    Foo foo;
    foo.member_var = 10;
    foo.member_func();
    

    3.:: for accessing static variables and methods of a class/struct or namespace. It can also be used to access variables and functions from another scope (actually class, struct, namespace are scopes in that case)

    int some_val = Foo::static_var;
    Foo::static_method();
    int max_int = std::numeric_limits<int>::max();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a class called Foo. Foo has three fields, which are all ints:
Right, so here the scenario: I've created a class called DiaryPage that inherites from
I've a created a class called Animal as shown below: class Animal{ int eyes,legs;
I created a class in C++ called Commands (file name commands.cpp). I've taken that
I have created a class called ShortestTime. I have some functions within it that
I've created a class called website, and want to access it like a variable
I'm new to OOP. I created this class called Site that is extended but
I need some help here. I've created a child class called MyEditorRow from DevExpress
I have created a class called aptSchedule which, like its name suggests, keeps track
I've created a class called SpecialArray and I'd like to customize what sort of

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.