no function declarations for operator

后端 未结 2 793
你的背包
你的背包 2020-12-07 06:12

I get this error message:

testbench.vhd:16:22: no function declarations for operator \"+\"

at this line:

    Z &         


        
2条回答
  •  眼角桃花
    2020-12-07 06:15

    The error message is pretty clear. There is no function declarations for operator "+" which can add two unsigneds together and return a std_logic_vector. In the package numeric_std, there is however an opertor "+" which can add two unsigneds together and return an unsigned.

    So, if you add another type conversion to convert the result of the addition back to a std_logic_vector the compiler can choose the version of the "+" operator that returns an unsigned.

    Z <= std_logic_vector(unsigned(X) + unsigned(Y));
    

    Overloading only works if there is exactly one fit for function, procedure or operator. If there is less than one, then there is no version for the compiler to choose; if there is more than one, the compiler doesn't know which one to choose and there is an ambiguity which needs to be sorted out.

    Actually, you don't need to resize Y: the "+" operator is happy as long as one of the operands is the same width as the result.

    https://www.edaplayground.com/x/4VJE

提交回复
热议问题