Thread: can't figure out the compiler error

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    6

    can't figure out the compiler error

    Can someone please help me with this compiler error........any help would be much appreciated

    Thanks

    Deleting intermediate files and output files for project 'Binary Search Tree ADT - Win32 Debug'.
    --------------------Configuration: Binary Search Tree ADT - Win32 Debug--------------------
    Compiling...
    tree.cpp
    treetester.cpp
    c:\program files\microsoft visual studio\myprojects\binary search tree adt\tree.h(377) : error C2270: 'PrintAncestors' : modifiers not allowed on nonmember functions
    c:\program files\microsoft visual studio\myprojects\binary search tree adt\tree.h(398) : error C2270: 'PrintAncestors' : modifiers not allowed on nonmember functions
    c:\program files\microsoft visual studio\myprojects\binary search tree adt\tree.h(402) : error C2270: 'PrintValue' : modifiers not allowed on nonmember functions
    c:\program files\microsoft visual studio\myprojects\binary search tree adt\tree.h(438) : error C2270: 'PrintValue' : modifiers not allowed on nonmember functions
    Error executing cl.exe.

    Binary Search Tree ADT.exe - 4 error(s), 0 warning(s)

    ******************************
    *****************************
    *******HERE'S THE CODE*********

    template<class ItemType>
    void PrintAncestors(TreeNode<ItemType>* tree, ItemType value) const;
    //prototype

    template<class ItemType>
    void TreeType<ItemType>::Ancestors(ItemType value) const
    //calss recursive function PrintAncestors to print the ancestors
    {
    PrintAncestors(root, value);
    }

    template<class ItemType>
    void PrintAncestors(TreeNode<ItemType>* tree, ItemType value) const
    {
    if(tree->info != value)
    {
    cout << tree->info << endl;
    if(tree->info < value)
    PrintAncestors(tree->right, value);
    else
    PrintAncestors(tree->left, value);
    }
    }


    template<class ItemType>
    void PrintValue(TreeType<ItemType> tree, ItemType value) const;
    //prototype

    template<class ItemType>
    void TreeType<ItemType>::PrintValuesOfTree(ItemType value) const
    //calls function PrintValue to print values of tree less than value
    {
    PrintValue(tree, value);
    }

    template<class ItemType>
    void PrintValue(TreeType<ItemType> tree, ItemType value) const
    //Pre: tree has been initialized
    //Post: Prints values in tree that contain values that are less than value

    {
    ItemType item;
    bool finished = false;

    if(tree.IsEmpty())
    return 0;
    else
    {
    tree.ResetTree(IN_ORDER);
    //process stops when larger value is reached

    while(!finished)
    {
    tree.GetNextItem(item,finished, IN_ORDER);
    if(item < value)
    cout << item << endl;
    else
    finished = true;
    }

    }
    }

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    because

    template<class ItemType>
    void PrintAncestors(TreeNode<ItemType>* tree, ItemType value) const;

    is a function not a member function. You can't use "const" after the prototypeand definition header because it doesn't mean anything. Same goes for the other function.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    6
    Thank you

    now my code compiles.... much appreciated.

    later

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM