1

I'm writing a non-trivial class that holds a collection of key-value pairs and during compilation I receive a very strange error that I cannot figure out. In a function, extremely similar to this function here, but without the context due to the complexity of the code needed, I receive the error:

TValue& operator[](const TKey& key) {
   TDict::Node* node = mData.Begin(); // ERROR: 'node' was not declared in this scope
                                      // -_- ... really? 
   do {
      if(node->Data.Key == key) {
         return node->Data.Value;
      }
   } while(node != mData.End());

   this->Add(key, TValue());
   return this->End()->Data.Value;
}  
  • TDict is a typedef that expands into List<KeyValuePair<TKey, TValue> >
  • TDict::Node is visible during the compilation process.
  • No other variable is called node, obviously.
  • This is a member function.

I am not asking for the code needed to correct this, but rather a synopsis of potential situations where an error like this can occur.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
zackery.fix
  • 1,786
  • 2
  • 11
  • 20

1 Answers1

3

Its expands into List, where TKVPair is a typedef that expands into KeyValuePair.

It's dependent-name, so, you should use typename

typename TDict::Node* node = mData.Begin();

read Where and why do I have to put the "template" and "typename" keywords? for more information.

Community
  • 1
  • 1
ForEveR
  • 55,233
  • 2
  • 119
  • 133
  • Thank you. GCC should have move intuitive error messages. I have seen this before, but could not remember how to fix it. Again, thank you! – zackery.fix Dec 09 '13 at 07:11