I've been using C#/.NET for the past decade or two, but am updating an old C++/MFC application for a client. I know a lot has changed since I last worked with C++, but this one kind of threw me.
I have the following structure:
typedef struct _FILTERINFO {
int nCustomerID;
CString sCustomerName;
} FILTERINFO, *LPFILTERINFO;
And Visual Studio 2019 gives me a warning:
Warning C26495 Variable '_FILTERINFO::nCustomerID' is uninitialized. Always initialize a member variable (type.6).
So, what is the problem here and how would I initialize the variable? As you can see, I don't have a constructor. I don't need them for structures now do I?
NOTE: Looking into this further, I see my app defines other struct that for some reason do not get this same warning. It seems specific to about two or three declarations.
Drop the typedef, you are doing C++, so instead write:
struct FILTERINFO
{
int nCustomerID=0;
CString sCustomerName;
};
and
typedef FILTERINFO* LPFILTERINFO;
Normally it is better to not do a typedef of a pointer, use instead FILTERINFO* because sometimes you get unexpected behavior when used with const
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With