2 u010208436 u010208436 于 2013.10.06 14:17 提问

c++模板类包含typedef 指针函数,vs2012编译错误
#include "stdafx.h"
#include<stdexcept>
#ifndef ToozyBinaryTreeHead
#define ToozyBinaryTreeHead
template <class T>
class ToozyBinaryTree{
public:
    typedef bool (*findFunc)(typename const ToozyBinaryTree<T>::ToozyBinaryTreeNode*,const T*); 
    static const int LEFT = 1;
    static const int RIGHT = 2;

    struct ToozyBinaryTreeNode{
        ToozyBinaryTreeNode *left;
        ToozyBinaryTreeNode *right;
        ToozyBinaryTreeNode *nextNode;
        T value;
        ToozyBinaryTreeNode(const T *v){
            value = *v;
            left = nullptr;
            right = nullptr;
            nextNode = nullptr;
        }
    };

    findFunc findFunction;
    ToozyBinaryTree(ToozyBinaryTreeNode *root);
    ToozyBinaryTree(T *v);
    ~ToozyBinaryTree();
    const ToozyBinaryTreeNode *find(const T *value) const;
    const ToozyBinaryTreeNode *add(const ToozyBinaryTreeNode *parent,const T *value,int type);
    const ToozyBinaryTreeNode *getRoot();
protected:
    ToozyBinaryTreeNode* _root;
    ToozyBinaryTreeNode* _lastNode;
};

这样子:
typedef bool (*findFunc)(typename const ToozyBinaryTree::ToozyBinaryTreeNode*,const T*);
应该怎么改?

1个回答

tlxzsz
tlxzsz   2014.02.17 19:15

typedef bool (*findFunc)(typename const ToozyBinaryTree::ToozyBinaryTreeNode*,const T*);
改为bool (*findFunc)(typename const ToozyBinaryTree::ToozyBinaryTreeNode*,const T*);
typedef的用法不是这样用的。去查查type的用法吧。
findFunc findFunction;这句多余了。去掉

Csdn user default icon
上传中...
上传图片
插入图片