0

My program is very easy, all the mess happens around the passing of the ofstream pointer as shown below.

Main programm:

int main()
{...
ofstream otf;
otf.open("hex_movie.xyz");
....
write(int (1),oc,nx,ny,otf,ck)
}

And in the write.h, it begins with

int write(int TYPE,int *oc,int nx,int ny,ofstream otf, double ck)
{.... return 0;}

I used Xcode to debug it, and it shows (only on the line of the write fucntion, sorry I cannot upload a screen shot)

Xcode/GGK/GGK/ggk.cpp:110:28: Call to implicitly-deleted copy constructor of 'ofstream' (aka 'basic_ofstream')

Can anybody help me with this, thank you very much! :)

Zilinium
  • 11
  • 3
  • possible duplicate of ["ofstream" as function argument](http://stackoverflow.com/questions/9658720/ofstream-as-function-argument) –  Mar 18 '15 at 09:24

2 Answers2

3

In the signature of the function

int write(int TYPE,int *oc,int nx,int ny,ofstream otf, double ck)

the argument otf is of type ofstream, which means call by value; consequently, otf will be a copy of the agrument of the caller. You could change the signature to

int write(int TYPE,int *oc,int nx,int ny,ofstream& otf, double ck)

which will use call by reference and will use the same object as the caller.

Codor
  • 17,447
  • 9
  • 29
  • 56
  • Got it! I'm just a beginner, thank you very much! : ) I'll tick the answer later, for it has been solved so quick! LOL – Zilinium Mar 18 '15 at 09:29
2

You are currently passing by value otf try passing it by reference

int write(int TYPE,int *oc,int nx,int ny,ofstream& otf, double ck)
axelduch
  • 10,769
  • 2
  • 31
  • 50
  • I dont know whether it is a typo, but its ofstream&, as addressed by the 1st comment. Thank you anyway – Zilinium Mar 18 '15 at 09:31