C ++ virtual function task

Possible duplicate:
Overloading an overloaded database in C ++

I have a class like this:

class Object {
public:
    int alignment() const;
    virtual void alignment(int i);
};

that I am trying to subclass as follows:

class Sub : public Object {
public:
    virtual void alignment(int i);
};

then

Sub *sub = new Sub();
sub->alignment(10);
int a = sub->alignment();

The compiler (clang 1.0) generates an error: "Too few arguments to call the function expected 1 have 0." I do not understand why a virtual function that takes an argument gets confused with a non-virtual constant. Can someone explain why?

+3
source share
4 answers

Yes. Executing this function hides the overload function in the base class. Add the following to your class Subto fix this:

using Object::alignment;
+3
source

Finding a name doesn't work the way you think.

Sub , alignment. ... . , . , Sub Object. , , .

, alignment Object , . , .

, Sub, , .

+3

, :
int a = sub->Object::alignment();

public, , Space_C0wb0y

+1
source

int a = sub-> alignment ();

You did not specify a parameter in which it expects it.

-2
source

All Articles