Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Inheritance

Inheritance

Scheduled Pinned Locked Moved C / C++ / MFC
oophelptutorialquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 0 Offline
    0 Offline
    0v3rloader
    wrote on last edited by
    #1

    Hello, I have been having this compiling issue today and I don't really know what I am doing wrong. Nothing better than an example to make myself understood thus consider the following example:

    class objA
    {
    public:
    objA(){};
    ~objA(){};

    public:
    virtual bool Setup(int){};
    bool Setup(float){};
    };

    class objB : public objA
    {
    public:
    objB(){};
    ~objB(){};

    public:
    virtual bool Setup(int){};
    };

    class C
    {
    public:
    C(){};
    ~C(){};

    public:
    bool doTest()
    {
    objB b;

    	b.Setup(100);	
    	b.Setup(0.0001); // warning C4244: 'argument' : 
    			 // conversion from 'const double' to 'int', possible loss of data
    };
    

    };

    Why am I getting this warning? I mean, shouldn't the compiler automatically use the float-version method, or are there any rules I am aware of? Any insights as to why this is happening will be greatly appreciated. Thanks, David

    B C 2 Replies Last reply
    0
    • 0 0v3rloader

      Hello, I have been having this compiling issue today and I don't really know what I am doing wrong. Nothing better than an example to make myself understood thus consider the following example:

      class objA
      {
      public:
      objA(){};
      ~objA(){};

      public:
      virtual bool Setup(int){};
      bool Setup(float){};
      };

      class objB : public objA
      {
      public:
      objB(){};
      ~objB(){};

      public:
      virtual bool Setup(int){};
      };

      class C
      {
      public:
      C(){};
      ~C(){};

      public:
      bool doTest()
      {
      objB b;

      	b.Setup(100);	
      	b.Setup(0.0001); // warning C4244: 'argument' : 
      			 // conversion from 'const double' to 'int', possible loss of data
      };
      

      };

      Why am I getting this warning? I mean, shouldn't the compiler automatically use the float-version method, or are there any rules I am aware of? Any insights as to why this is happening will be greatly appreciated. Thanks, David

      B Offline
      B Offline
      Budric B
      wrote on last edited by
      #2

      Because your Setup function is declared to accept an integer class objB : public objA { public: objB(){}; ~objB(){}; public: virtual bool Setup(int){}; //see, it's an integer, 0.00001 is not };

      1 Reply Last reply
      0
      • 0 0v3rloader

        Hello, I have been having this compiling issue today and I don't really know what I am doing wrong. Nothing better than an example to make myself understood thus consider the following example:

        class objA
        {
        public:
        objA(){};
        ~objA(){};

        public:
        virtual bool Setup(int){};
        bool Setup(float){};
        };

        class objB : public objA
        {
        public:
        objB(){};
        ~objB(){};

        public:
        virtual bool Setup(int){};
        };

        class C
        {
        public:
        C(){};
        ~C(){};

        public:
        bool doTest()
        {
        objB b;

        	b.Setup(100);	
        	b.Setup(0.0001); // warning C4244: 'argument' : 
        			 // conversion from 'const double' to 'int', possible loss of data
        };
        

        };

        Why am I getting this warning? I mean, shouldn't the compiler automatically use the float-version method, or are there any rules I am aware of? Any insights as to why this is happening will be greatly appreciated. Thanks, David

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #3

        Since the 0.0001 is set-up as a const double type by the compiler, it is going to have to cast it since you have not provided an explicit cast. I'm not familiar with all the rules each compiler will use in order to decide what cast to use, but at least you are given a warning about the cast. Have you tried this

        b.Setup((double)0.0001);

        Chris Meech I am Canadian. [heard in a local bar] Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups