I am trying to re-implement a singly-linked list class with template
s. Below is the code that has troubles.
template<typename T>
class list
{
private:
struct node
{
node* next;
T data;
node( T d ) : next( nullptr ), data( d ) {}
};
node* first_node;
size_t m_size;
public:
list() : first_node( nullptr ), size( 0 ) {}
// ...
};
Everything is ok, until I try to use (ie in a method push_back()
) members of a node*
type variable. Example:
void push_back( const T& data )
{
node* temp = first_node;
while( temp->next )
{
temp = temp->next;
}
// ...
}
While I am typing temp->
, Visual Studio's IntelliSense should bring up a context menu to show the members of the node
structure. It is not doing this. Also, when I hover the next
word in my code, the tooltip looks like this:
Let me say it clear: I don't get any debugging error, but my question is: Why isn't Visual Studio 2013 able to compute those things?
This is not unexpected and is not an error. You are writing a template, the IntelliSense parser doesn't know what concrete type the next member belongs to. That cannot be known until later in your code you instantiate, say, a list<int>
. So it gives you what it knows, it certainly does know that temp->next
is a list<T>::node
and tells you so, just not for which particular kind of list
. So it prefixes <unknown>
.
You could certainly argue that it should display template class<T> list<T>::node::next
instead. Not so sure that spins everybody's propeller, or if this is at all capability of the EDG parser (doubtful), you can make your case at Connect and file a bug report.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.