0

This is my sample code. I used it like this, but I had an error from //error-line.

The following error appeared:

Variable has incomplete type 'std::TestCpp:: TestString'

class TestCpp{
    public:
        any value;
        struct TestString;

        TestCpp(TestString Value){ // error
            this->value = static_cast<any>(Value);
            cout << Value;
        }

};
Michael Kemmerzell
  • 4,802
  • 4
  • 27
  • 43
Ambrose Jesuraj
  • 103
  • 1
  • 10

1 Answers1

1

You are using an instance of TestString in the constructor of TestCpp before it has been defined. You should first define TestString, then define the constructor of TestCpp. My guess is you don't want to define TestString where you declared it. To achieve that, you can do this by defining the constructor of TestCpp in a source file for instance.

// header file
struct TestCpp
{
    std::any _value;
    struct TestString;
    TestCpp(TestString); // declare here, define in source file    
};

// source file
#include "header_file"

struct TestCpp::TestString { /* ... */ };

TestCpp::TestCpp(TestString) { /* ... */ }
mfnx
  • 2,894
  • 1
  • 12
  • 28