Unhelpful Errors...boo

I get the following 163: error: expected `;' before 'buck' , which I believe is rather meaningless when considering the code.

A relevant portion of code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template< class BoundType, class CountType >
CountType& BucketCounter<BoundType,CountType>::Classify( const BoundType& value )
{
    CountType* usedBucket = &_unclassified;  // Unclassified count

    BucketList::iterator buck;  // Line 163
    for( buck  = _buckets.begin();
         buck != _buckets.end();
         ++buck )
    {
        BucketType& thisBucket = *buck;

        if( thisBucket.Contains( value ) ){

            // Value belongs in this bucket
            usedBucket = &thisBucket.Count;
            break;
        }
    }


Where BuckeList is defined as:
1
2
3
typedef Bucket<BoundType,CountType> BucketType;
typedef std::vector<BucketType> BucketList;
typedef typename BucketList::iterator iterator;


Where Bucket is...
1
2
3
4
5
6
7
8
9
10
template< class BoundType, class CountType = int >
// BoundType  : type for upper/lower bounds/data being bucketed
// CountType : type for counting elements/hits into buckets
struct Bucket {

    BoundType LowerBound;
    BoundType UpperBound;
    CountType Count;

    std::string Tag;  // Space for extra info 


Can anyone shed some light on the problem? I'm fairly certain I've placed a ";" in the correct spot. :)
typename BucketList::iterator buck;

EDIT: The syntax "A::B" can be resolved in multiple ways. A could be a class/struct type and B a member variable or function; A could be a class/struct type and B another type; A could be a namespace and B could be a function, variable, or type.

The compiler is smart enough to figure out that A is a class/struct type, but not smart enough to realize that B is also a type, so it defaults to thinking B is a member variable. Which means it parses line 163 as

<variable> <variable> ;

which is not valid C++ syntax.

Adding the keyword "typename" tells the compiler that A::B is in fact a type, not a variable.
Last edited on
I understand. Thank you very much. I'll be sure to watch for this problem in the future.
Topic archived. No new replies allowed.