In C++ is it bad to have an undefined variable as a function argument which has a default argument value?
I believe this would lead to undefined behavior but I've seen it in some preexisting code and I don't see any warnings being outputted and wanted to confirm the behavior I should be expecting
Header File - header.h
#ifndef HEADER_H
#define HEADER_H
class aClass
{
int someFunctionA(int aValue = 0);
virtual int someFunctionB(int aValue = 0);
}
#endif
CPP File - body.cpp
int aClass::someFunctionA(int aValue)
{
if (aValue == 0)
{
return 0;
}
else
{
return 1;
}
}
int aClass::someFunctionB(int aValue)
{
if (aValue == 0)
{
return 0;
}
else
{
return 1;
}
}
int main(int argc, char **argv, char **envp)
{
int uninitializedInt;
int initializedInt = 1;
aClass example = new aClass();
aClass.someFunctionA(); // Expecting this to return 0
aClass.someFunctionB(); // Expecting this to return 0
aClass.someFunctionA(uninitializedInt); // Expecting this to be undefined behaviour
aClass.someFunctionB(uninitializedInt); // Expecting this to be undefined behaviour
aClass.someFunctionA(initializedInt); // Expecting this to return 1
aClass.someFunctionB(initializedInt); // Expecting this to return 1
}
Are my expectations as per my code comments correct?