Reputation: 1
File: A.h
class A
{
public:
struct x X;
int show()
{
x.member_variable ? 0: -1;
}
};
Now if A.cpp is complied which includes A.h (which is actually in a huge project space) we see that x.member_variable value is not as expected. But if remove the show() method and place it in A.cpp the code behaves fine - meaning that x.member_variable value is correct.
How such a thing may happen - one thing we saw from objdump is that if the function is defined in A.h the the method is treated as inline function which otherwise is not if defined in A.cpp?
How the code can behave differently altogether?
Upvotes: 0
Views: 234
Reputation: 137770
Did you forget the return
?
int show()
{
return x.member_variable ? 0: -1;
}
Without it, the code is still legal but the value returned will be somewhat random. There may happen to be a correlation between the behavior and where you put the code.
Upvotes: 4