Frio_Lazzlo
July 3rd, 2007, 01:06 PM
Hello people.
Im battling with this few days now and i couldnt find anything about this topic on the internet, so i decided to register here. Im having problems with my console program and i would like some help : ).
(using dev-c++ if it matters)
Problem: i want to make a class member (a file input object) that is only initialized one time when the first object of this class is created.
Some background: at the beginning, the program is creating the files i want to open in my class later if its needed.
I have tryed making these objects static members of the class but the problem is that they are initialized before main() when the files i want to open dont exist..., making them a regular member will always open them and at huge file it would take unnecesery long time because if they are open they are used frequently.
<code>
//Main.cpp
#include "a.h" // where my class is
int main()
{
createmyfiles();
if(condition)
{
for(int x = 0; x < 10; x++)
{
a* myobject = new a;
a->dosomething();
delete a;
}
}
}
//in a.h
#ifndef _a_h_
#define _a_h_
#include "myinputclass.h"
class a
{
public:
//...
myinputobject my; // the member i am talking about
};
#endif</code>
Thanks in advance.
Im battling with this few days now and i couldnt find anything about this topic on the internet, so i decided to register here. Im having problems with my console program and i would like some help : ).
(using dev-c++ if it matters)
Problem: i want to make a class member (a file input object) that is only initialized one time when the first object of this class is created.
Some background: at the beginning, the program is creating the files i want to open in my class later if its needed.
I have tryed making these objects static members of the class but the problem is that they are initialized before main() when the files i want to open dont exist..., making them a regular member will always open them and at huge file it would take unnecesery long time because if they are open they are used frequently.
<code>
//Main.cpp
#include "a.h" // where my class is
int main()
{
createmyfiles();
if(condition)
{
for(int x = 0; x < 10; x++)
{
a* myobject = new a;
a->dosomething();
delete a;
}
}
}
//in a.h
#ifndef _a_h_
#define _a_h_
#include "myinputclass.h"
class a
{
public:
//...
myinputobject my; // the member i am talking about
};
#endif</code>
Thanks in advance.