NVH wrote:
Yeah, sorry about that.
Here's a more clear one:
===================================
#include <iostream>
using namespace std;
class Foo
{
public:
Foo (const Foo &num)
{
number = num.number;
cout << 1 << endl;
} // Copy constructor
template <typename T>
Foo (const T &num)
{
number = num;
cout << 2 << endl;
} // Conversion constructor
void print (void)
{
cout << number << endl;
}
private:
auto int number; // Complier points to here for 1st
error
Drop the auto. It's illegal here since you're not actually allocating
anything but rather just declaring a class that will be allocated
(either automatically or dynamically) later.
};
void main (void)
{
auto Foo G(5);
auto Foo H(G); // Compiler points to here for 2nd error
Again, drop the auto. It's legal here, but it's the default, and no one
uses it since it only adds clutter and verbosity.
G.print(); // Display the content
H.print(); // Display the content
}
========================================
The compiler keeps on saying:
error C2071: 'number' : illegal storage class
error C2668: 'Foo::Foo' : ambiguous call to overloaded
function
The problem is not with the code. It is legal, and various relatively
conformant compilers accept it fine (once the auto is deleted above,
that is). Thus, I will venture to guess that you are using VC++ 6,
which is non-conformant when it comes to templates. If that is the
case, you'll want to upgrade or search for a work-around that is
suitable for your situation. One might be to get rid of the copy
constructor Foo::Foo(const Foo&). For others, you'll want to ask in
Microsoft newsgroup since this is a compiler-specific issue. Several
such groups can be found here:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
Cheers! --M