Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
Strange errors occurring when compiling…

Strange errors occurring when compiling the 64-bit version of an application, error C2664

Apr 05 2013
Author:

Sometimes you may see questions about strange errors generated by the compiler when building 64-bit code.

A question may look in the following way:

//Class definition
class Type1 {...};
class Type2 {...};
class A
{
  public:
  ...
  void Func1(Type1* t1.....);
  void Func1(Type2& t2.....);
  ...
};
//Using Func1 function
A obj;
Type2 t2;
...
obj.Func1(t2,...);
...

This code successfully compiles in the 32-bit mode but the compiler generates the error C2664 (Type2 cannot be cast to Type1*) when trying to build the 64-bit version. Although the function taking Type2& as the argument is defined, the compiler, due to some reason, tries to use the function taking Type1* as the argument. What is the matter?

Most likely, the problem is in the other parameters which were replaced by dots in the example. Here is one more example of the code:

class Type1 {};
class Type2 {};
class A
{
public:
void Func1(Type1* t1, unsigned &);
void Func1(Type2& t2, size_t &);
};
void use() {
  A obj;
  Type2 t2;
  unsigned u;
  obj.Func1(t2, u);
}

It successfully compiles in the 32-bit mode. But in the 64-bit mode the both functions fail to work. The compiler considers the first function a better candidate because its second parameter meets the condition. Yet it announces that the first argument does not suit: error C2664: 'void A::Func1(Type1 *,unsigned int &)' : cannot convert parameter 1 from 'Type2' to 'Type1 *'. The solution is to carefully study the other arguments and modify the code as needed.

Popular related articles


Comments (0)

Next comments next comments
close comment form