J
jsanga
What are the major benifits / drawbacks to the following code?
myheader.h
#include <vector>
struct MyStruct {
int f1;
float f2;
...
};
typedef std::vector< MyStruct > STRUCTURES;
class STRUCTURES_TOO : public std::vector< MyStruct > {};
The reason for asking is; I'm trying to reduce header file includes,
improve compile time and write better conforming code. The issue here
is when other classes need to pass around STRUCTURES as a parameter, I
am forced to include "myheader.h" for the definition.
anotherheader.h
#inlcude "myheader.h"
class MyClass {
public:
DoSomething( const STRUCTURES &s ); // require myheader.h
};
However, by declaring STRUCTURES_TOO I am able to do the following
anotherheader.h
class STRUCTURES_TOO; // Just forward ref the class
class MyClass {
public:
DoSomething( const STRUCTURES_TOO &s );
};
I know the STL doesn't have virtual destructors, so derrived classes
are frowned upon. But in this case I don't have the problem of passing
around base classes.
myheader.h
#include <vector>
struct MyStruct {
int f1;
float f2;
...
};
typedef std::vector< MyStruct > STRUCTURES;
class STRUCTURES_TOO : public std::vector< MyStruct > {};
The reason for asking is; I'm trying to reduce header file includes,
improve compile time and write better conforming code. The issue here
is when other classes need to pass around STRUCTURES as a parameter, I
am forced to include "myheader.h" for the definition.
anotherheader.h
#inlcude "myheader.h"
class MyClass {
public:
DoSomething( const STRUCTURES &s ); // require myheader.h
};
However, by declaring STRUCTURES_TOO I am able to do the following
anotherheader.h
class STRUCTURES_TOO; // Just forward ref the class
class MyClass {
public:
DoSomething( const STRUCTURES_TOO &s );
};
I know the STL doesn't have virtual destructors, so derrived classes
are frowned upon. But in this case I don't have the problem of passing
around base classes.