if your underlying list storage used a vector instead of pointers, you could extract it from that as well. there are pros and cons to such a simulated list, so this isn't always worth doing.
With your current Node structure it is entirely possible to make calculating the length a constant time operation, at the cost of increased complexity for insertion and delete.
A better choice would be to maintain a specific Head object that keeps the length of the list as a member variable, in addition to the first Node pointer. Then when you pass the Head object around (which I would actually name “List”), you can get the length.
1 2 3 4 5 6 7 8 9 10 11 12 13
template <typename T>
struct Node
{
T data;
Node* next;
};
template <typename T>
struct List
{
int size;
Node* head;
};
Now whenever you insert or delete nodes, you must also adjust the size in the head object.
BTW, there is no point in maintaining a Node* back for a singly-linked list. (See ne555’s comment following)