Microsoft KB Archive/140604: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "<" to "<")
Line 79: Line 79:
{
{
public:
public:
   int f(int) {cout &lt;&lt; &quot;In A::f(int)!!!\n&quot;;return 0;}
   int f(int) {cout << &quot;In A::f(int)!!!\n&quot;;return 0;}
};
};


Line 85: Line 85:
{
{
public:
public:
   int f(char*){cout &lt;&lt; &quot;In D::f(char*)!!!\n&quot;;return 0;}
   int f(char*){cout << &quot;In D::f(char*)!!!\n&quot;;return 0;}
   using A::f;        // &lt;&lt;== move this above the int f(char*)
   using A::f;        // <<== move this above the int f(char*)
                       //  declaration to fix the problem.
                       //  declaration to fix the problem.
};
};
Line 94: Line 94:
   B d;
   B d;
   d.A::f(1);
   d.A::f(1);
   d.f(1);            // &lt;&lt;== C2664 happens here
   d.f(1);            // <<== C2664 happens here
   d.f(&quot;Hi There&quot;);
   d.f(&quot;Hi There&quot;);
}
}

Revision as of 15:53, 20 July 2020

Knowledge Base


Article ID: 140604

Article Last Modified on 7/5/2005



APPLIES TO

  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Enterprise Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++ 6.0 Standard Edition



This article was previously published under Q140604

SYMPTOMS

Attempting to overload member functions located in a base class from a derived class with a 'using' declaration, may result in the following compiler error:

error C2664: 'function': cannot convert parameter 'number' from 'type1' to 'type2'

CAUSE

This particular problem occurs if the member functions that are being overloaded are declared before the 'using' declaration in the class definition.

RESOLUTION

Place the 'using' declaration above the declarations for the member functions you want to overload. See the comments in the following code sample:

Sample Code

#include "iostream.h"

class A
{
public:
   int f(int) {cout << "In A::f(int)!!!\n";return 0;}
};

class B : public A
{
public:
   int f(char*){cout << "In D::f(char*)!!!\n";return 0;}
   using A::f;        // <<== move this above the int f(char*)
                      //  declaration to fix the problem.
};

void main()
{
   B d;
   d.A::f(1);
   d.f(1);            // <<== C2664 happens here
   d.f("Hi There");
}
                

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.


REFERENCES

For more information on the 'using' declaration, please see:

\Visual C++ Books\C/C++\C++ Language\Reference\Declarations\ Namespaces\using Declaration



Additional query words: kbVC400bug

Keywords: kbbug kbfix kbnoupdate kbcompiler KB140604