Ofstream in class - attempt to reference a remote function

I have a member variable in the class, its type ofstreamand constructor, which contains a string parameter:

class dogs
{
public:
    ofstream dogsFile;

    dogs(string location)
    {

    }
};

The following error will appear:

Error 2 of error C2280: 'std :: basic_ofstream> :: basic_ofstream (const std :: basic_ofstream> &)': attempt to link to a remote function c: \ users \ pc \ documents \ visual studio 2013 \ projects \ database \ database \ database .cpp 26 1 Database

I tried this code again, but instead of using a string, I used char *:

class dogs
{
public:
    ofstream dogsFile;

    dogs(char* location)
    {

    }
};

And the error has disappeared. What for? why does the line cause an error?

Edit: This is all the code:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>

using namespace std;


class dogs
{ 
    ofstream dogsFile;

public:
    dogs(string location)
    {

    }
};

int main(int argc, _TCHAR* argv[])
{
    dogs dog = dogs("dog.bin");
    return 1;
}
+4
2

. :

dogs *dog = new dogs("dog.bin");

, . .

( "dog.bin" ) , "=" . .

,

dogs dog("dog.bin");

.

+2

- , V++.

dogs, , std::ofstream, ++ 11.

, , [12.8/9] [12.8/11]. . .

dogs dog = dogs("dog.bin");

dogs dog ( , , ).

, .

Clang 3.5. GCC, , , ( - ).

, V++, OP, dogs, - , std::string . :

dogs(const string& location)

dogs(int a) //And change the call accordingly, of course.

dogs(A a) //And change the call accordingly (A is a user-defined class).

V++, .

, std::string, , , . , , , .

, :

dogs(dogs&& arg) : dogsFile(std::move(arg.dogsFile)) { }

, , std::string .

, V++ .

0

All Articles