abstract class member cannot be overladed?

This is a discussion on abstract class member cannot be overladed? within the C++ Programming forums, part of the General Programming Boards category; I'm getting the following error when I compile: Code: error: 'virtual const int Base::getX() const' and 'virtual const int Base::getY() ...

  1. #1
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391

    abstract class member cannot be overladed?

    I'm getting the following error when I compile:
    Code:
    error: 'virtual const int Base::getX() const' and 'virtual const int Base::getY() const' cannot be overloaded
    Here's a look at the files in question:

    main.cpp
    Code:
    #include <iostream>
    #include "derived.h"
     
    int main(){
     
      Derived( 1, 1 );
     
      return 0;
    }
    derived.h
    Code:
    #ifndef DERIVED_H_
    #define DERIVED_H_
     
    #include <iostream>
     
    class Base{
      public:
        Base( int x, int y ) : x(x), y(y) {}
        virtual const int getX() const = 0; // Error is with these two lines
       virtual const int getY() const = 0;
     
      protected:
        int x, y;
    };
     
    class Derived : public Base{
      public:
        Derived( int x, int y );
        const int getX() const;
        const int getY() const;
        const int getZ() const;
     
        friend std::ostream& operator<<( std::ostream& os, const Derived& d );
        friend class Modifier;
     
      private:
        int z;
        void setZ( int val );
    };
     
    #endif
    derived.cpp
    Code:
    #include "derived.h"
     
    Derived::Derived( int x, int y )
    : Base(x,y), z( x ) {}
     
    const int Derived::getX() const{ return x; }
    const int Derived::getY() const{ return y; }
    const int Derived::getZ() const{ return z; }
     
    void Derived::setZ( int val ){ z = val; }
     
    std::ostream& operator<<( std::ostream& os, const Derived& d ){
      os << d.x << " " << d.y << " " << d.z;
      return os;
    }
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    I am afraid that I cannot duplicate the error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    ???

    The screwy thing is i only get the error on 1 computer and the code compiles just fine on another... ?

    Is there any cases where you can't overload base class members in this fashion (I'm not aware of any). This really sucks because I need it to compile on the machine that's giving me the error.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by dudeomanodude View Post
    ???

    The screwy thing is i only get the error on 1 computer and the code compiles just fine on another... ?

    Is there any cases where you can't overload base class members in this fashion (I'm not aware of any). This really sucks because I need it to compile on the machine that's giving me the error.
    Compiles fine on g++... which compiler are you using where it doesn't compile?

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,785
    What OS/Compiler version?

    gg

  6. #6
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    cygwin/g++
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Let's try this with just one file:
    Code:
    #include <iostream>
    
    class Base{
    public:
        Base( int x, int y ) : x(x), y(y) {}
        virtual const int getX() const = 0;
        virtual const int getY() const = 0;
    
    protected:
        int x, y;
    };
    
    class Derived : public Base {
    public:
        Derived( int x, int y );
        const int getX() const;
        const int getY() const;
        const int getZ() const;
    
        friend std::ostream& operator<<( std::ostream& os, const Derived& d );
        friend class Modifier;
    
    private:
        int z;
        void setZ( int val );
    };
    
    int main() {
        Derived( 1, 1 );
    
        return 0;
    }
    
    Derived::Derived( int x, int y ) : Base(x,y), z( x ) {}
    
    const int Derived::getX() const { return x; }
    const int Derived::getY() const { return y; }
    const int Derived::getZ() const { return z; }
    
    void Derived::setZ( int val ){ z = val; }
    
    std::ostream& operator<<( std::ostream& os, const Derived& d ) {
        os << d.x << " " << d.y << " " << d.z;
        return os;
    }
    Do you get any compilation errors when compiling the above program?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Do you get any compilation errors when compiling the above program?
    No. I even copied the contents of the files into new files in a new directory, compiled and everything was OK.

    But if I go back into the troubled files and compile I get the error. Now what the heck is the deal with that? I mean, they're identical now.

    ???

    EDIT: also, the Makefile is identical too.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Maybe try a make clean and then rebuild from scratch, though I would think that stale object files would only cause a linking error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    In the old directory (where the problem was), there's also some dependencies that have since been renamed (i.e. old_dependancy.d is no longer needed, and has been replaced by new_dependancy.d. Those dependancies came from old_dependancy.cpp and new_dependancy.cpp respectively).

    The only thing I can think of is that make is relying on the info old_dependancy.d has, and can't resolve something.

    It is make that is throwing the error....
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  11. #11
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    yea, I was cleaning the directory, but I was getting rid of the old dependancies. I guess that was the problem.

    EDIT: make that "wasn't" getting rid of the old dependancies.
    Last edited by dudeomanodude; 12-10-2008 at 10:15 AM.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  2. Replies: 6
    Last Post: 04-27-2006, 10:55 AM
  3. SystemTray class
    By jair in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2003, 06:27 PM
  4. DLL class member functions
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 07-11-2003, 06:59 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21