F
Filipe Sousa
Hi!
I always see code written like this:
void foo()
{
int b = bar();
int g = goo();
// k and g is never changed
//...
}
instead of using const
void foo()
{
const int b = bar();
const int g = goo();
// k and g is never changed
//...
}
IMO we should use const whenever is possible or am I wrong?
class Foo {
std::string var;
public:
//...
const std::string& get_var() const { return var; }
}
Foo f;
what should I use?
this:
const std::string s = f.var()
or this:
const std::string& s = f.var()
I always see code written like this:
void foo()
{
int b = bar();
int g = goo();
// k and g is never changed
//...
}
instead of using const
void foo()
{
const int b = bar();
const int g = goo();
// k and g is never changed
//...
}
IMO we should use const whenever is possible or am I wrong?
class Foo {
std::string var;
public:
//...
const std::string& get_var() const { return var; }
}
Foo f;
what should I use?
this:
const std::string s = f.var()
or this:
const std::string& s = f.var()