While I am learning C++ based on how develop in modern PHP frameworks I decided to use the Dependency Injection pattern with services as Singletons.
For making myself clear let suppose we have the collowing classes:
class B {
public:
B(){};
}
class A{
public:
// Dependency Injecting class B into class A
A(B b):b(b){}
private:
const B b;
}
So in this example I wondered if I will gain better performance if I used pointer instead of an Object. In other words would it be better if class A
had been:
class A{
public:
// Dependency Injecting class B into class A
A(B* b):b(b){}
private:
const B *b;
}
Also, what is the downside in the pointer-based approach?
const B* b;
" Not related, but I think you should really use spaces according to grammar:const B *b;
because grouping isconst B;
and*b