-2

I think I have asked this question long time ago, but can't find it. I see this code snippet.

template <
    unsigned int N
    >
class pyramid_down : noncopyable
{
public:

    COMPILE_TIME_ASSERT(N > 0);

    template <typename T>
    vector<double,2> point_down (
        const vector<T,2>& p
    ) const
    {
        const double ratio = (N-1.0)/N;
        return (p - 0.3)*ratio;
    }

the vector<double,2> seems to be a vector with two elments. Where can I find the c++ lenguage explanation for this? I couldn't find it here : http://www.cplusplus.com/reference/vector/vector/

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • 2
    Where did you get that code from? Are you sure it's actually `std::vector`? – cigien Oct 02 '20 at 03:55
  • That snippet alone can't fully explain what's going on there. – user4581301 Oct 02 '20 at 04:04
  • 2
    The `std::vector` template has a second type that specifies an allocator type. `std::vector` is not valid. Your `vector` type, whatever it is, is some non-standard type that differs from `std::vector` – Peter Oct 02 '20 at 04:35
  • thanks all, it was dlib::vector from http://dlib.net – Chan Kim Oct 02 '20 at 04:37
  • @ChanKim Why does your template not have stated `dlib::vector` instead of just `vector`? You left your code wide open for these types of errors by not specifying the namespace. – PaulMcKenzie Oct 02 '20 at 04:39
  • You should probably go ahead and close the question as "not reproducible". – cigien Oct 02 '20 at 04:39
  • @cigien at the beginning of the program, there was namespace dlib {. it was by my mistake not checking the namespace before(there is no using std). should I delete this question? I think it still provides some info to beginners that we should first check the namespace though. – Chan Kim Oct 02 '20 at 06:43
  • It's up to you, but this issue is covered clearly [here](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice). – cigien Oct 02 '20 at 12:32
  • yeah, but those who don't know there is 'different namespace' problem cannot search the web and arrive at the link you provided. I'd rather leave it at that so that people like me can get hint from it. – Chan Kim Oct 03 '20 at 02:31

1 Answers1

1

It is not std::vector.

std::vector does not accept an integer in its 2nd template parameter, nor does it have an operator- defined, so clearly the vector in this example is not std::vector but is a different type of vector. Maybe a mathematical vector, or a graphical vector, who knows. There is no way to know from the limited snippet given.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • yeah, right. I thought it's strange when I saw p -0.3 and should have looked in more. It was the vector in dlib. `namespace dlib { template < typename T, long NR = 3 > class vector;` – Chan Kim Oct 02 '20 at 04:35