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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:59:33+00:00 2026-05-21T04:59:33+00:00

Example: long a; BoundedCounter e; So I want to assign the value of the

  • 0

Example:

long a;
BoundedCounter e;

So I want to assign the value of the private variable counter in the class to a.

a=e;

Tried using this:

long int & operator=(long b)
{
    b=counter;
    return b;
}

and

long int & operator=(long b, BoundedCounter &a)
{
   b=a.getCounter();
   return b;
}

Which return a compile error:

cannot convert BoundedCounter' to
long int’ in assignment

and

`long int& operator=(long int, BoundedCounter&)’ must be a nonstatic member function

How do I define an operator= outside of the class which will work when the left side is a normal variable and not an object?

  • 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-21T04:59:34+00:00Added an answer on May 21, 2026 at 4:59 am

    operator= is unsuitable here as the left-hand side of the assignment is a primitive type (and you cannot define operator= for primitive types). Try giving BoundedCounter an operator long, e.g.:

    class BoundedCounter
    {
    public:
        // ...
        operator long() const
        {
            return counter;
            // or return getCounter();
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone provide a simple example using getopt.pas with short and long command line
Here's an example I have. public int getDelta() { long time = getTime(); int
Given I have a long phrase, say, in line :12 , as this example:
well basically can long long int hold number with 100 symbols? for example can
I have modeled an AJAX search after this example a long time ago. I
For example: long xx = ..; //is xx in range of an int type?
I have for example the long number 12345678901 and I want to get separately
For example I have long list of buttons: <input type=button name=clickbutton onclick='dosomething(this)'> But instead
Here is example: class A { public long ParentId; public string ParentName; public string
I have something like this: long[] f = new long[4]{1,10,100,1000}; I want to divide

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.