W
wij
Hi:
I don't understand why the following program doesn't compile.
Can anyone explain?
/* Build: g++ t.cpp */
#include <iostream>
class Foo {
Foo(const Foo& rhs) { std::cout << "Foo(const Foo&) "; };
public:
Foo(int) { std::cout << "Foo(int) "; };
};
static Foo tab[1]={ Foo(0) };
int main(void)
{
return(0);
}
g++ says error: `Foo::Foo(const Foo&)' is private
But, if the copy constructor is made public, then
the executable prints 'Foo(int) '.
$g++ t.cpp
$./a.out
Foo(int)
It looked that only Foo(int) is called, the copy constructor is
never used. But, if I hide the copy constructor, g++ complains.
How can I hide the copy constructor in this case?
IJ. Wang
I don't understand why the following program doesn't compile.
Can anyone explain?
/* Build: g++ t.cpp */
#include <iostream>
class Foo {
Foo(const Foo& rhs) { std::cout << "Foo(const Foo&) "; };
public:
Foo(int) { std::cout << "Foo(int) "; };
};
static Foo tab[1]={ Foo(0) };
int main(void)
{
return(0);
}
g++ says error: `Foo::Foo(const Foo&)' is private
But, if the copy constructor is made public, then
the executable prints 'Foo(int) '.
$g++ t.cpp
$./a.out
Foo(int)
It looked that only Foo(int) is called, the copy constructor is
never used. But, if I hide the copy constructor, g++ complains.
How can I hide the copy constructor in this case?
IJ. Wang