"can't convert parameter" error

I

Ian Lazarus

// why is the error message being generated?
// Microsoft Visual C/C++ 5.0

class Bar
{
public:
void Log(const char* p){ }
};

class Foo : public Bar
{
public:
void Log(int x){ }
};

int main()
{
Foo foo;
foo.Log("foo bar"); // error message below

return(0);
}

// error C2664: 'Log' : cannot convert parameter 1 from 'char [8]' to 'int'
 
W

White Wolf

Ian said:
// why is the error message being generated?
// Microsoft Visual C/C++ 5.0

class Bar
{
public:
void Log(const char* p){ }
};

class Foo : public Bar
{
public:

using Bar::Log;
void Log(int x){ }
};

int main()
{
Foo foo;
foo.Log("foo bar"); // error message below

return(0);
}

// error C2664: 'Log' : cannot convert parameter 1 from 'char [8]' to
'int'

Bar::Log hides Foo:Log as a name.
 
O

Oliver Fleischmann

// why is the error message being generated?
// Microsoft Visual C/C++ 5.0

class Bar
{
public:
void Log(const char* p){ }
};

class Foo : public Bar
{
public:
void Log(int x){ }
};

int main()
{
Foo foo;
foo.Log("foo bar"); // error message below

return(0);
}

// error C2664: 'Log' : cannot convert parameter 1 from 'char [8]' to 'int'


Hi,

this error is created, because the "Log" method of your class "Foo"
takes an integer as parameter.
"Foo" inherets the Log function from Bar but you overwrite it in Foo
so it's parameter isn't a "const char *" anymore but your "int x".

Olli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,420
Latest member
ZitaVos505

Latest Threads

Top