Templates and lambdas, "incomplete type is not allowed" and

Right, it's been a while since I've done anything in C++ so if it's something really stupid gimme a break :)
Also I've never really used lambdas either so same again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    typedef unsigned __int8 B1;
    typedef unsigned __int16 B2;

    class Device{
    private:
    protected:
        template<typename T> class WCommand;
        template<typename T> class RCommand;
        template<typename T> class RWCommand;

    public:
        RWCommand<B1> nodeID{
            0,
            [](const B1& value){return std::string((char*)value);},
            [](const std::string& str){return (B1)str[0];}
        };
        //code skipped

        template<typename T>class RWCommand: public WCommand{
        private:
            T rValue;
            std::function<T(const std::string)> fromBytes;
        public:
            RWCommand(B2 address, std::string(*serialiser)(const T& value), T(*deserialiser)(const std::string str)):
                WCommand(address, serialiser), fromBytes(deserialiser){}
            RWCommand(B2 address, std::function<std::string(const T&)> serialiser, std::function<T(const std::string&)>):
                WComand(address, serialiser), fromBytes(deserialiser){}
            //code skipped
            }
        };
    //code skipped
    };


VSC15 gives the following errors:

Error: incomplete type is not allowed

over the identifier nodeID


Error:
more than one conversion function from "lambda []std::string (const Device::B1 &value)->std::string" to "<error-type>" applies:
    function "Device::Device::lambda []std::string (const Device::B1 &value)->std::string::operator std::string (*)(const Device::B1 &value)() const"
    function "Device::Device::lambda []std::string (const Device::B1 &value)->std::string::operator std::string (*)(const Device::B1 &value)() const"
    function "Device::Device::lambda []std::string (const Device::B1 &value)->std::string::operator std::string (*)(const Device::B1 &value)() const"
    function "Device::Device::lambda []std::string (const Device::B1 &value)->std::string::operator std::string (*)(const Device::B1 &value)() const"

Same error given above the opening brace of both lamdas
Last edited on
In line 12, RWCommand<B1> is an incomplete type
http://coliru.stacked-crooked.com/a/91e7c8207395ce21
JLBorges wrote:
In line 12, RWCommand<B1> is an incomplete type
http://coliru.stacked-crooked.com/a/91e7c8207395ce21


Seems you didn't read the entire post

But I suppose you could say I should have been a little clearer and asked why I'm getting these errors? Although it doesn't seem to make much sense to point out things I've already said so I though it was kind of implied :p
> why I'm getting these errors?

Isn't that obvious?

A program is ill-formed if the definition of any object gives the object an incomplete type
...
A class that has been declared but not defined, an enumeration type in certain contexts, or an array of unknown size or of incomplete element type, is an incompletely-defined object type. Incompletely-defined object types and the void types are incomplete types. Objects shall not be defined to have an incomplete type.
[Footnote: The size and layout of an instance of an incompletely-defined object type is unknown.]
-IS
JLBorges beat me to it, but for variety here's how other compilers describe this problem:

clang:
1
2
3
4
5
6
main.cpp:15:23: error: implicit instantiation of undefined template 'Device::RWCommand<unsigned char>'
        RWCommand<B1> nodeID{
                      ^
main.cpp:12:36: note: template is declared here
        template<typename T> class RWCommand;
                                   ^


gcc:
1
2
3
4
5
6
ain.cpp:19:9: error: field 'nodeID' has incomplete type 'Device::RWCommand<unsigned char>'
         };
         ^
main.cpp:12:36: note: declaration of 'class Device::RWCommand<unsigned char>'
         template<typename T> class RWCommand;
                                    ^


intel:
1
2
3
test.cc(15): error: incomplete type is not allowed
          RWCommand<B1> nodeID{
                        ^


oracle:
"test.cc", line 15: Error: In this declaration "nodeID" is of an incomplete type "Device::RWCommand<unsigned char>".
Okay I'll apologise for that as I moved the templates above and it's fine... Just gotta work around with the variables instead but I'm sure I'll find a way to make it fit how I need it.

As for the other errors which is what I was more frustrated about... They just vanished after correcting the incomplete type. [Damn compilers :) ]

Oh well... Cheers... Suppose it really has been a while.
Topic archived. No new replies allowed.