Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. passing parameters

passing parameters

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasecryptographyquestionlearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sirrius
    wrote on last edited by
    #1

    I have a problem and need somebody to show me the light. I am trying to pass a struct through a template class called table. I keep generating an error of c2783 and cant for the life of me figure out why or what is wrong. The code is directly from a text book. Here is the code that is generating that error. template class table { table() { size_t i; used = 0; for(i=0; i void insert(const recordType &entry) { bool already_present; size_t index; assert(entry.key >= 0); //SET INDEX SO THAT DATA[INDEX] IS THE SPOT TO PLACE THE NEW ENTRY find_index(&entry.key,already_present,index); //IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY. if(!already_present) { assert(size() < CAPACITY); index = hash(entry.key); while(!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; } }; struct tractor { int key; }; void main() { table ta; tractor t; t.key=44; ta.insert(t); }

    M P 2 Replies Last reply
    0
    • S Sirrius

      I have a problem and need somebody to show me the light. I am trying to pass a struct through a template class called table. I keep generating an error of c2783 and cant for the life of me figure out why or what is wrong. The code is directly from a text book. Here is the code that is generating that error. template class table { table() { size_t i; used = 0; for(i=0; i void insert(const recordType &entry) { bool already_present; size_t index; assert(entry.key >= 0); //SET INDEX SO THAT DATA[INDEX] IS THE SPOT TO PLACE THE NEW ENTRY find_index(&entry.key,already_present,index); //IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY. if(!already_present) { assert(size() < CAPACITY); index = hash(entry.key); while(!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; } }; struct tractor { int key; }; void main() { table ta; tractor t; t.key=44; ta.insert(t); }

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Well, you didn't say where the error is happening, so I can only guess:

      template<class recordType>
      void insert(const recordType &entry)

      Take out the redundant template there, you only need that if the method has different template params than the class that it's in. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Actual sign at the laundromat I go to: "No tinting or dying."

      S 1 Reply Last reply
      0
      • M Michael Dunn

        Well, you didn't say where the error is happening, so I can only guess:

        template<class recordType>
        void insert(const recordType &entry)

        Take out the redundant template there, you only need that if the method has different template params than the class that it's in. --Mike-- Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber Actual sign at the laundromat I go to: "No tinting or dying."

        S Offline
        S Offline
        Sirrius
        wrote on last edited by
        #3

        sorry about not being more specific, but it seems to not like the way I am sending the parameter in the void main(). I will try your method and see what happends. thanks. Also when I double-click on the error, it goes directly to the find_index() call in the insert function. Such as: see the comment below.

        void main()
        {
        table ta;
        tractor t;
        t.key=44;
        ta.insert(t); // this line seems to be generating the errors.

        }

        1 Reply Last reply
        0
        • S Sirrius

          I have a problem and need somebody to show me the light. I am trying to pass a struct through a template class called table. I keep generating an error of c2783 and cant for the life of me figure out why or what is wrong. The code is directly from a text book. Here is the code that is generating that error. template class table { table() { size_t i; used = 0; for(i=0; i void insert(const recordType &entry) { bool already_present; size_t index; assert(entry.key >= 0); //SET INDEX SO THAT DATA[INDEX] IS THE SPOT TO PLACE THE NEW ENTRY find_index(&entry.key,already_present,index); //IF THE KEY WASN'T ALREADY THERE, THEN FIND THE LOCATION FOR THE NEW ENTRY. if(!already_present) { assert(size() < CAPACITY); index = hash(entry.key); while(!is_vacant(index)) index = next_index(index); ++used; } data[index] = entry; } }; struct tractor { int key; }; void main() { table ta; tractor t; t.key=44; ta.insert(t); }

          P Offline
          P Offline
          Phil Hamer
          wrote on last edited by
          #4

          In searching Google, I actually found code very similar to this except they pass entry.key by value instead of taking address: find_index(entry.key,already_present,index); You probably just made a typo.

          S 1 Reply Last reply
          0
          • P Phil Hamer

            In searching Google, I actually found code very similar to this except they pass entry.key by value instead of taking address: find_index(entry.key,already_present,index); You probably just made a typo.

            S Offline
            S Offline
            Sirrius
            wrote on last edited by
            #5

            no, I got this choppy code out of my text book and you are right, it is entry.key but I have tried it that way and several different ways and it still fails to compile.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups