S
Steve
A coworker just returned to C++ coding after a long hiatus and asked me how
to accomplish this task. What seemed liked simple issue, we have been unable
to resolve. He has declared a structure that includes an MFC class and wants
to initialize it at declaration time. Something like this:
In the h. file:
namespace SomeNamespace
{
struct SomeStruct
{
long theNumber;
CPoint thePoint;
};
SomeStruct arrssTheArray[] =
{
{
1,
CPoint(1,1)
},
{
2,
CPoint(2,2)
}
};
};
I have about 5 years experience in C\C++ but am self-taught so I can't rely
on any training background and I have been unable to find a similar example
of code. The compiler compliains that is cannot cast the long to a
"SomeStruct".
We also tried:
In the .h file:
namespace SomeNamespace
{
struct SomeStruct
{
long theNumber;
CPoint thePoint;
};
SomeStruct arrssTheArray[];
};
In the .cpp file:
#include "SomeFile.h"
SomeNamespace::SomeStruct SomeNamespace::arrssTheArray[] =
{
{
1,
CPoint(1,1)
},
{
2,
CPoint(2,2)
}
};
In this case the compiler complains about a redefinition. Can this task even
be done? Where can one go for information of this sort? I have about ~4
books on C\C++ but cannot seem to find a definitive answer for issues like
this. Thanks all.
Steve
to accomplish this task. What seemed liked simple issue, we have been unable
to resolve. He has declared a structure that includes an MFC class and wants
to initialize it at declaration time. Something like this:
In the h. file:
namespace SomeNamespace
{
struct SomeStruct
{
long theNumber;
CPoint thePoint;
};
SomeStruct arrssTheArray[] =
{
{
1,
CPoint(1,1)
},
{
2,
CPoint(2,2)
}
};
};
I have about 5 years experience in C\C++ but am self-taught so I can't rely
on any training background and I have been unable to find a similar example
of code. The compiler compliains that is cannot cast the long to a
"SomeStruct".
We also tried:
In the .h file:
namespace SomeNamespace
{
struct SomeStruct
{
long theNumber;
CPoint thePoint;
};
SomeStruct arrssTheArray[];
};
In the .cpp file:
#include "SomeFile.h"
SomeNamespace::SomeStruct SomeNamespace::arrssTheArray[] =
{
{
1,
CPoint(1,1)
},
{
2,
CPoint(2,2)
}
};
In this case the compiler complains about a redefinition. Can this task even
be done? Where can one go for information of this sort? I have about ~4
books on C\C++ but cannot seem to find a definitive answer for issues like
this. Thanks all.
Steve