Hi,all
I am implementing the required assignment and face compiler error which i do not understand.
Here is my class:

class fooPlayer
{
public:
       fooPlayerfunc(){}//doing something here
       char askYesNo(std::string question);
};

class fooPlayerFactory
{
public:
   virtual std::auto_ptr<fooPlayer> MakePlayerX() const;
   virtual std::auto_ptr<fooPlayer> MakePlayerO() const;
private:
   std::auto_ptr<fooPlayer> MakePlayer(char letter) const;
   std::auto_ptr<fooPlayer> my_player;

};

Here is how i implement my class:

auto_ptr<fooPlayer> fooPlayerFactory:: MakePlayer(char letter) const
{
       my_player->fooPlayerfunc();
	return my_player;
}

auto_ptr<fooPlayer> fooPlayerFactory::MakePlayerX() const
{
    char go_first = my_player->askYesNo("Do you require the first move?");
      MakePlayer(go_first);
      return my_player;
}

auto_ptr<fooPlayer> fooPlayerFactory::MakePlayerO() const
{
	return my_player;
}

here is my mian()

int main()
{
  fooPlayerFactory factory;
  factory.MakePlayerX();
  factory.MakePlayerO();
}

I got the error:

error C2558: class 'std::auto_ptr<_Ty>' : no copy constructor available or copy constructor is declared 'explicit'

I do not understand what is that mean and how i could solve this problem??
Thanks.

Hi,
I understand the document.
But still do not know how to change my code here.

Remove the "private:" in fooPlayerFactory and compile again. What happens? And please give us a hint by writing which line causes the error message

The auto_ptr copy constructor (which you are calling each time you return my_player) only allows a non-const parameter because it needs to clear the pointer from the source after moving it to the destination. All of your functions are declared const, so the appropriate copy constructor (i.e. one which copies a const auto_ptr) doesn't exist.
The immediate solution to your error is simply to remove the const specifier from all of the functions.

This article has been dead for over six months. Start a new discussion instead.