- Mohd Syafiq Johar Arrifin: It is OK or bad practice if I do that?
CFileOperation *OP = new CFileOperation(); // Calling constructor OP.do_demo(); delete OP; // Call deconstructor
The only bad practice is to do dynamic allocation instead of letting the compiler handle it.
CFileOperation OP; // Calling constructor OP.do_demo(); } // Call deconstructor
-
In addition, generalize your code.
public: CFileOperation(string filename) { filehandle=FileOpen(filename,FILE_WRITE|FILE_CSV); /////////////// CFileOperation OP("fractals.csv"); // Calling constructor
Thank you William Roeder.
`1. The only bad practice is to do dynamic allocation instead of letting the compiler handle it.`
Did you mean from this,, the bad practice that currently I'm doing is to use function pointer instead of:
/* let [METHOD1] = */ CFileOperation OP; // Calling constructor OP.do_demo(); } // Call deconstructor
And, that mean there's no problem to code FOpen in constructor & FClose in deconstructor and this kind of code is safe to use without causing any bug/problem?
I already forget this method name/keyword since not using it for a long time but I will refer this as METHOD1 for temporary, and I think it's a good time to ask & recap..
- What is the different between [METHOD1] & function pointer?
- When to use idle METHOD1 or function pointer..

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I want to ask about file operation inside class
Consider this is the basic code that I copy from here (MQL4 FileOpen)
And,, I remake it into class. But this time the code a bit different
**Please ignore if I do not place the class parameter/payload, error handling & etc
**or even if there's mistake on code such as forget semicolon, class expect param but I do not pass & etc. Because that's not the question
Question:
From what we can see here, `FileOpen` is placed on constructor & `FileClose`is place on de-constructor. It is OK or bad practice if I do that?
The idea behind this, because after the FileOpen, I have to run a few function before the file need to be close.
Since the function itself too long and I plan to split into it's individual function in class and call it at once on constructor so that the code can easily read & troubleshooting.