This is not related to classes. I have a function that returns a constant based on the input. A minimum working example related to my question is added below.
#include <iostream>
namespace surfaceArea
{
constexpr int triangle = 11;
constexpr int square = 25;
}
int getSurfaceArea(bool isTriangle)
{
return isTriangle? surfaceArea::triangle : surfaceArea::square;
}
int main ()
{
const int numSides = 3;
const bool isTriangle = (numSides == 3);
const int surface = getSurfaceArea(isTriangle);
std::cout << "Surface Area is " << surface;
return 0;
}
Should I use static or const for the function getSurfaceArea(bool isTriangle)
. That is as
const int getSurfaceArea(bool isTriangle)
or static int getSurfaceArea(bool isTriangle)
? What are the differences between these two keywords and What is the best practice to use in a similar scenario?