Error message from header file in Principles and Practice using C++

后端 未结 2 1695
感动是毒
感动是毒 2021-01-23 11:37

I\'ve just started learning C++ using Programming: Principles and Practice using C++. That book tells me to use a header file which sets things up for me. The header file in que

2条回答
  •  忘掉有多难
    2021-01-23 12:36

    (Are you sure that's the code you're compiling? where is max declared?)

    std::vector is a very strange beast which doesn't behave like std::vector for any other T.

    Unfortunately even though std::vector seems like the obvious choice in your case, it forces you to deal with the oddness of std::vector and it doesn't work with Stroustrup's Vector class template.

    The detailed explanation of the error is that Stroustrup's header re-defines vector to refer to his Vector template, which adds some range-checking to the element access operator (i.e. operator[], which is the one used when you say primes[i]). The redefined vector cannot be instantiated with bool because std::vector::operator[] does not return a normal reference, and the redefined vector expects it to do so.

提交回复
热议问题