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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:25:50+00:00 2026-05-27T20:25:50+00:00

Edit: I posted the whole class (striped a few for the error irrelevant things

  • 0

Edit: I posted the whole class (striped a few for the error irrelevant things out)

I made following class:

class packet
{public:char *  buffer;
    int     size;
    int     data;

    packet();
    packet(packet &text, int length=-1);
    packet(char * text, int length=-1);
    packet(int val);
    packet(char c);
    packet(double d);
    packet(float f);

    ~packet();

    packet &    operator=       (packet &text);
    packet      operator+       (packet &text);
    packet &    operator+=      (packet &text);
    packet &    operator|=      (packet &text);
    bool        operator==      (packet &text);
    bool        operator*=      (packet &text);
    bool        operator!=      (packet &text);

                operator char*  () const;
                operator int    () const;
                operator float  () const;
    char        operator []     (int pos)  const;
};

And I use the class like this:

    packet p = packet();

or

return packet();

And Visual Studio gives me this error:

test.cpp(162): error C2668: 'packet::packet' : ambiguous call to overloaded function
...packet.h(26): could be 'packet::packet(float)'
...packet.h(23): or       'packet::packet(int)'
...packet.h(22): or       'packet::packet(char *,int)'

Does anyone know what I am doing wrong here ? Why is this ambigous ?

PS: I think it has to do with the 4 operators at the bottom but I am a little hazy with overloading those kind of operators…

Solution: I got it working by marking some constructors as explicit:

class packet
{public:char *  buffer;
    int     size;
    int     data;

    packet();
    packet(packet &text, int length=-1);
    explicit packet(char * text, int length=-1);
    explicit packet(int val);
    explicit packet(char c);
    explicit packet(double d);
    explicit packet(float f);

    ~packet();

    packet &    operator=       (packet &text);
    packet      operator+       (packet &text);
    packet &    operator+=      (packet &text);
    packet &    operator|=      (packet &text);
    bool        operator==      (packet &text);
    bool        operator*=      (packet &text);
    bool        operator!=      (packet &text);

                operator char*  () const;
                operator int    () const;
                operator float  () const;
    char        operator []     (int pos)  const;
};
  • 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-27T20:25:50+00:00Added an answer on May 27, 2026 at 8:25 pm

    In case the error really occurs at the place where you try to assign the result of the function to a new variable, the problem could be your copy constructor. You should make the packet& in const so that it can be used with temporary objects:

    packet(const packet & text, int length=-1);
    

    The other constructors might come into play in this case if your class is implicitly convertible to int, float,….

    Due to such issues it is usually advisable to not add unnecessary conversion operators and mark constructors as explicit to avoid unexpected implicit conversions.

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

Sidebar

Related Questions

I’m developing MVC application and I have following classes in my model: public class
What are extension methods in .NET? EDIT: I have posted a follow up question
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
I posted another one on this,, but i had to edit it really much...
EDIT What small things which are too easy to overlook do I need to
Edit at bottom with solution I've seen a similar question to this posted before
#ifndef SLIST_H #define SLIST_H #include llist.h using namespace std; class slist:public llist{ public: slist();
i have the following code defining the gui of my app class Ui (object):
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: From another question I provided an answer that has links to a lot

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.