Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't name my C++ static functions with similar names
    primarykey
    data
    text
    <p>I have a C++ class where I declare two static methods that have (and they should have) similar names, but definitely not the <strong>same</strong> name. So I did this:</p> <pre><code>#include &lt;cstdio&gt; struct Cat; class Cat { public: int age; Cat * mother; Cat * father; Cat(){}; ~Cat(){}; static Cat* walk_to_min(Cat* c); static Cat* walk_to(Cat* c, int distance); }; </code></pre> <p>But when I try to compile, G++ gives me this:</p> <pre><code>cats.cpp:22: error: expected unqualified-id before ‘walk_to’ cats.cpp:22: error: expected ‘;’ before ‘walk_to’ </code></pre> <p>But if I change - for example - <code>walk_to</code> to <code>gogo</code> it works. So I guess it has something to do with the naming of these methods.</p> <p>What's going on? Why the methods can't be named like I want them to. Imagine a BST, where you have BST_delete and BST_delete_min, sometimes you want to have methods with similar names. What can I do?</p> <p><strong>Update</strong>. Sorry everyone, I wasn't showing the real code. this is the real code:</p> <pre><code>#include &lt;cstdio&gt; class BST { public: int key; BST* leftChild; BST* rightChild; BST(); BST(int t) : key(t) {} ~BST(){}; void inOrder(BST* bstree); void preOrder(BST* bstree); void postOrder(BST* bstree); static BST* delete_min(BST* root); static BST* delete(BST* root, int value); static BST* search(BST* element, int value); }; </code></pre> <p>by the way, both my methods delete_in and delete have their definitions empty:</p> <pre><code>BST* BST::delete_min(BST* root) { } BST* BST::delete(BST* root, int value) { } </code></pre> <p>and the error:</p> <pre><code>L2Q1-dunder-mifflin-cpp.cpp:21: error: expected unqualified-id before ‘delete’ L2Q1-dunder-mifflin-cpp.cpp:21: error: expected ‘;’ before ‘delete’ </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload