I want to know if there is any difference between 2 pointers (as data members) in a template class. For example:
template <typename E>
class Link
{
private:
E element;
Link* a;
Link<E>* b;
};
Is "a" analogous to "b", I wonder?
We can compare pointers if they are pointing to the same array. Relational pointers can be used to compare two pointers. Pointers can't be multiplied or divided.
When two pointers are compared, the result depends on the relative locations in the address space of the objects pointed to. If two pointers to object types both point to the same object, or both point one past the last element of the same array object, they compare equal.
Two pointer algorithm is one of the most commonly asked questions in any programming interview. This approach optimizes the runtime by utilizing some order (not necessarily sorting) of the data. It is generally applied on lists (arrays) and linked lists. This is generally used to search pairs in a sorted array.
Equality operator (==,!=) Pointers of the same type (after pointer conversions) can be compared for equality. Two pointers of the same type compare equal if and only if they are both null, both point to the same function, or both represent the same address (3.9. 2).
Both forms are valid. When the name of a class template is used inside the class template scope without template arguments, it resolves to the name of the "current" template specialization.
a
and b
have the same type.
It's the same rule that makes it possible for us to write for example:
template<typename T>
Foo<T>::Foo(Foo const&) = default;
... instead of the more verbose:
template<typename T>
Foo<T>::Foo(Foo<T> const&) = default;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With