I've been thinking lately with the method I'm using as many people suggest in making a class.
Some part of my code look like this :
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class test_t{
test_t( double _x ){
x = _x;
}
double get_x(){
return x;
}
private:
double x;
};
|
but after I tested...
Direct access to a variable is far more faster ( around twice as fast ) and I think it's breaking the OOP rules ( capsulation )
something like this
1 2 3
|
struct test_t{
double x;
}
|
changing the function from the first example to this though
1 2 3
|
double& get_x(){
return x;
}
|
have the same perfomence as direct access
there something I think might be a break trough for this, it's using "const" but I don't really know how to design a class that can be consted...
Hmmm, I think that the second one is what most people suggested because it does capsulation as what OOP code should be.
but if it's twice as slow or more that is quite bother some
Thank in advance and tell me if I'm misunderstood any part and please tell me your opinion.