I am having the problem: has initializer but incomplete type while using struct:
in a hpp file:
class A
{
private:
struct videoDT;
};
in a cpp file:
struct A::videoDT
{
videoDT(int b) : a(b){}
int a;
};
void test()
{
struct videoDT test(1);
}
Then I have the problem:
Error: has initializer but incomplete type
Thanks in advance
I think the problem is that test()
doesn't have access to A
's private types.
This compiles for me:
class A
{
private:
friend void test();
struct videoDT;
};
struct A::videoDT
{
videoDT(int b) : a(b){}
int a;
};
void test()
{
A::videoDT test(1);
}
In your test
function you declare a local type struct videoDT
, but never define it. Not surpisingly, the compiler complains about an object of incomplete type being initialized. End of story.
How did you expect it to work? If you wanted your declaration to use A::videoDT
type, then you should have used the qualified name for the type - A::videoDT
- since that's what that type is called. However, the code will not compile anyway, since A::videoDT
is private in A
and test
has no access to it.
In other words, it is hard to figure out what you were trying to do. Provide some explanations or code that make more sense.
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