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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:37:17+00:00 2026-05-26T14:37:17+00:00

I am trying to complete my assignment.which says In a Distance class create an

  • 0

I am trying to complete my assignment.which says In a Distance class create an overloaded * operator so that two distances can be multiplied together. Here is my program:

#include<iostream>
using namespace std;
class distance
{
private:
    int a;
public:
    distance():a(10){}
    distance(int x)
    {
        a=x;
    }
    void print()
    {
    cout<<"\n a = "<<a<<" \n ";
    }
    distance operator *(distance);
};
distance distance :: operator *(distance d)
{
    a=a*d.a;
    return distance(a);
}
int main()
{
distance d1,d2,d3;
d1.print();
d2.print();
d3.print();
d3=d1 * d2;
d3.print();
return 0;
}

But I get a compilation error saying:

'distance' : ambiguous symbol.

when I run it on VC++

But it runs fine on Turbo C (by minor change: #include<iostream.h>).

Please explain where am I getting wrong. Thanks in advance.

  • 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-26T14:37:18+00:00Added an answer on May 26, 2026 at 2:37 pm

    There’s already a function called std::distance, which you’re bringing into scope through using namespace std and which clashes with your distance class.

    Call your class something else (e.g. Distance) or, better yet, remove using namespace std.

    P.S. This is a nice illustration of why using namespace X in this manner usually isn’t a good idea.

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

Sidebar

Related Questions

Hi I am am trying to complete an assignment, where it is ok to
I'm trying to complete a regular expression that will pull out matches based on
im trying to getting auto complete working and i can do so fine when
I'm trying to create an auto-complete function for the ICSharpCode.TextEditor. But the fileTabs_KeyDown doesn't
I'm trying to complete an exercise to write a program that takes the following
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.
I am trying to complete a college assignment in Perl, and we've been told
I am trying to complete the tutorial at http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=438 It seems that the servlet
I have an assignment for a class that is to be done in C#.
I trying to complete this exercise; Write a Lisp function that takes as input

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.