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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:37+00:00 2026-05-27T11:39:37+00:00

I have a class Point and a class Rect . I want to have

  • 0

I have a class Point and a class Rect. I want to have two constructors for the Rect: One with a Point and a dimension (width, height) and one with two Points (top left, bottom right). Now it turns out that Point also can be seen as a dimension, so instead of creating a Dimension class I want to use my Point, basically like this:

class Point{...};
typedef Dimension Point;

class Rect{
    public:
        Rect(Point, Point);
        Rect(Point, Dimension);
}

So the question is: Does the compiler make a difference between Point and Dimension? I tried it, the message ist “call of overloaded Rect(Point, Point) is ambiguous.”.

How should I do that? Preferably without inheritance 🙂

EDIT

I understood now that it’s the same to the compiler. But there is another scenario wher I need that.

I have a Point. The coordinates can be in a carthesian system (x, y) or GPS coordinates (lon, lat). It’s perfectly ok for me to call the components x0 and x1 so I want to use only one class.

Now I want to calculate the distance between the two points and my idea is as follows:

typedef PointLonLat Point;
typedef PointXY Point;

double distance(PointLonLat, PointLonLat);
double distance(PointXY, PointXY);

PointLonLat p1(10, 10);
PointLonLat p2(11, 11);

double dist = distance(p1, p2); // the correct implementation is used

I know it doesn’t work like that. But would the answer to that also be “make two classes”?

  • 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-27T11:39:38+00:00Added an answer on May 27, 2026 at 11:39 am

    If point and dimension don’t have identical behaviour, then your typedef is a logic error. If they do, then you don’t need two constructors.


    In response to your edit

    For the example you’ve provided, what you have is two classes that store the same amount of data but have different behaviour. It’s analagous to std::size_t and void* – they’re both the same number of bits to the underlying hardware, but the language’s type system gives them totally different meanings.

    Your example could be solved by using two different classes, or by using a template class to avoid duplication like this:

    enum CoordinateSystem {
      Geographic,
      Cartesian
    };
    
    template<CoordinateSystem C>
    struct Point {
      double x,y;
    };
    
    double distance(Point<Cartesian>, Point<Cartesian>);
    double distance(Point<Geographic>, Point<Geographic>);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class class ChartLine{ protected: vector<Point> line; // points connecting the line
I have an example class containing two data points: public enum Sort { First,
I have simple class Point with two fields of type double . I asked
Let's say I have a class Point: class Point { int x, y; public:
I have a ViewModel class that contains a list of points, and I am
I have the points by the end of the GenerateButton class but now that
I have the following class: public class SimplePolygon { Point[] pointCollection; public SimplePolygon(Point[] pointCollection)
If you have a Point3 class and have a method called Distance , should
Suppose I have class A { public: void print(){cout<<A; }}; class B: public A
say I have this class: class animal { function noise() { print 'woof'; }

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.