Hi friends,
--Qt Questions
I'm currently starting Qt programming and i have some questions:
class Foo
{
...
static QList<Area*> *areas;
QList<Camera*> cameras;
...
}
class Foo
{
...
static QList<Area*> *areas;
QList<Camera*> cameras;
...
}
To copy to clipboard, switch view to plain text mode
{Considerations-> Camera and Area are normal classes, no Qt involved.}
1)I have these two objects, should i (in the destructor) call delete or delete [] for them?
2)Should i call delete for each Camera* and Area* object?
3)What would change in the first and in the second answer if the Foo class was derivated from QObject?
--Non-Qt questions
These are questions that always haunted me and never got answered:
1)What's the big catch in using pointers, i know some cases that pointers are good (like when we want to point something ) but when there's the option of choosing between pointer or non-pointer what parameters should I obey to choose one of them? Like:
class Foo
{
Foo(){};
~Foo(){};
void callMe() { cout<<"im alive"; };
}
void main()
{
Foo *f = new Foo(); //what are the advantages/disadivantages of using a pointer here instead of Foo f();
f->callMe();
delete f;
return;
}
class Foo
{
Foo(){};
~Foo(){};
void callMe() { cout<<"im alive"; };
}
void main()
{
Foo *f = new Foo(); //what are the advantages/disadivantages of using a pointer here instead of Foo f();
f->callMe();
delete f;
return;
}
To copy to clipboard, switch view to plain text mode
2)
class Foo
{
Foo(){};
~Foo(){};
}
void main()
{
Foo f();
Foo *p_f = &f;
delete p_f; //does 'f' gets deleted here or can i continue using it?
createFoo(p_f);
//is p_f still valid here? i mean, wasn't the object f destroyed after leaving createFoo function?
return;
}
void createFoo(Foo* p_f)
{
Foo f();
p_f = &f;
}
class Foo
{
Foo(){};
~Foo(){};
}
void main()
{
Foo f();
Foo *p_f = &f;
delete p_f; //does 'f' gets deleted here or can i continue using it?
createFoo(p_f);
//is p_f still valid here? i mean, wasn't the object f destroyed after leaving createFoo function?
return;
}
void createFoo(Foo* p_f)
{
Foo f();
p_f = &f;
}
To copy to clipboard, switch view to plain text mode
Thank you!
Bookmarks