Like Tree2Likes
  • 1 Post By Elkvis
  • 1 Post By Elkvis

A simple example of hashtable source code

This is a discussion on A simple example of hashtable source code within the C++ Programming forums, part of the General Programming Boards category; I was looking at that example snippet. I tried compiling it but it didnt work. My compiler complains about the ...

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    2

    A simple example of hashtable source code

    I was looking at that example snippet. I tried compiling it but it didnt work. My compiler complains about the node declaration part: Node defined as both function and variable

    Code:
    struct NODE
    {
       Node(const char* Key1 = "\0", const char* fName = "\0",
    
             const char *tele ="\0", const double sal = 0.0 )
       {
          strcpy(Key, Key1);
          strcpy(FullName, fName);
          strcpy(Tele_No, tele);
          Salary = sal;
          Tax = 0.005 * Salary;
          next = NULL;
       }
       char Key[SIZE_KEY];
       char FullName[SIZE_VALUE1];
       char Tele_No[SIZE_VALUE2];
       double Salary;
       double Tax;
       Node *next;
    
    };
    Notice the second node is defined as a function. Thats what I was confused about as well... while looking at the code, and so decided to test it out.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,391
    that will not compile. what I suspect is going on here is that the function is supposed to be the constructor for the struct. the only problem is that they don't have the same name. NODE != Node.
    King Mir likes this.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    2
    Quote Originally Posted by Elkvis View Post
    that will not compile. what I suspect is going on here is that the function is supposed to be the constructor for the struct. the only problem is that they don't have the same name. NODE != Node.


    Thanks, works now after renaming 'Node'. Interesting, I never knew structs could have constructors...Its not mentioned on the main tutorial site.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    2,391
    the only difference between a struct and a class is the default access level. in a class, the default access level is private, unless specified otherwise, whereas in a struct, the default access level is public.
    King Mir likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is object code the same as assembly source code?
    By c_weed in forum Tech Board
    Replies: 3
    Last Post: 01-05-2012, 06:25 PM
  2. How to reduce the source code to a more simple one ???
    By spurs01 in forum C Programming
    Replies: 6
    Last Post: 11-16-2009, 02:42 AM
  3. HashTable help?
    By -EquinoX- in forum C Programming
    Replies: 66
    Last Post: 03-31-2008, 12:15 AM
  4. good place for some simple c++ source?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-05-2002, 04:45 PM
  5. Replies: 1
    Last Post: 01-29-2002, 01:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21