Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to pass a pointer as a parameter to a member of fstream that points to a file
    text
    copied!<p>/* Thanks to anyone looking at this who might attempt to answer it. I'm really not trying to waste anyone's time here, but I have beat my head on this for about three days. I realize it is probably very simple for someone who understands it. I have tried most every possible combination I can think of and still get compiler errors. </p> <p>C:\random\RNDNUMTEST.cpp(41) : error C2102: '&amp;' requires l-value</p> <p>I am trying to pass a pointer as a parameter to a function makeRndmNumber() for the member function fstream.open(). I want to open the file in RNDNUMTEST.cpp and then pass it to makeRndmNumber() so that it can be modified in some way. I have looked online for help, including this website, but I feel like I am overlooking something important or simple or maybe I am just missing the concept altogether. </p> <p>This isn't for homework, I'm not a college student. Although I did go to school for it, it has been over 10 years since I've done any programming and I never really understood this that well to begin with. Any suggestions would be appreciated. </p> <pre><code>// These are only excerpts from the actual files. // RndmNum_Class.h file typedef void(fstream::*fStream_MPT)(const char*); // fStream_MPT (Member Pointer Type) class RandomNumber { public: RandomNumber(); ~RandomNumber() {}; static void loadDigits(double, double, char array[]); static int getLastNDigits(char array[], int); static int makeRndmNumber(int, int, fStream_MPT); }; //*************************************************************8 //RndmNum_Class.cpp file int RandomNumber::makeRndmNumber(int seed, int _fileSize, fStream_MPT FILE) { ...... } //**************************************************************/ // RNDNUMTEST.cpp file #include "RndmNum_Class.h" int main() { const char* RNDM_FILE = "c:\\RandomFile.txt"; fstream FStream_Obj; // FStream_Obj.open(RNDM_FILE); fStream_MPT FileMembPtr = &amp;FStream_Obj.open(RNDM_FILE); //fStream_MPT FileMembPtr = &amp;fstream::open; int seed = 297814; int size = 20000; cout &lt;&lt; RandomNumber::makeRndmNumber(seed, size, FileMembPtr); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload