   C++ implicit construction of arguments
  I have a class ImageHandle whose constructor takes a const reference to another class called ImgDataStruct.I also have a function which takes an ImageHandle as an argument.I always thought that I had to do something likefoo(ImgHandle(ImgDataStruct(args to IDS constructor)));but I discovered on accident that if I leave out the ImgHandle and instead dofoo(ImgDataStruct(args to IDS constructor));It still works. How can this be? I am passing a ImgDataStruct and it is somehow being implicitly converted to an ImageHandle even though I don't have any conversion operators or anything.class ImgHandle{    imageManager::ImageID myid;    public:    ImgHandle(): myid(imageManager::NullID()) {}    ImgHandle(const ImgDataStruct& imgdata): myid(imageManager::Instance().GetImageID(imgdata)) {}    void draw(SDL_Surface *screen, Sint16 screenx, Sint16 screeny, OptSdlRect clip = OptSdlRect(), Uint8 alpha = 255) const    {   assert(myid != imageManager::NullID());   imageManager::Instance().draw_perSurfaceAlpha(myid, screen, screenx, screeny, clip.get_ptr(), alpha);    }    operator bool() const {return myid != imageManager::NullID();}};
Quote:Original post by StoryyellerIt still works. How can this be? I am passing a ImgDataStruct and it is somehow being implicitly converted to an ImageHandle even though I don't have any conversion operators or anything.You do, however, have a constructor that takes a const ImgDataStruct&, and according to MSDN, "C++ constructors that have just one parameter automatically perform implicit type conversion."  Did you want your ImgHandle constructor to be explicit?   ;  Well I guess it's a good thing since it saves a little typing. It's just really surprising behavior to me.   ;Quote:Original post by Storyyellereven though I don't have any conversion operators or anything.A constructor that can take exactly one argument, and is not marked as explicit, qualifies as "a conversion operator". :)   