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. Function() question...

Function() question...

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 5 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.
  • N Nish Nishant

    Christian Graus wrote: s.SetName("a") // You allowed a char, which is one character "a" ??? Shouldn't this be 'a'??? Nish


    Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #5

    Yeah, but at least I spotted why he couldn't access the function.... Seriously, you're right, of course. *blush* Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

    R N 2 Replies Last reply
    0
    • S SilverShalkin

      ok... a functoin is declaring somthng like voide SetName(char Name) { } correct? then if you want to use that in your program you could do somthing like int main() { SetName("Judy") return 0; } now... even though this wont do anything... "because there isnt anything int eh SetName function... this would work right? i declared my void SetName(char Name); in a header class named Student so: void Student::SetName(char Name); { } int main() { char SName[32]; cin >> SName; SetName(SName); return 0; } wouldnt this work... what am i forgetting... i keep getting a undeclared identities thing. Thanks all! ~SilverShalkin :rose:

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #6

      SilverShalkin wrote: voide SetName(char Name) { } correct? A global function, yes. SilverShalkin wrote: int main() { SetName("Judy") return 0; } So long as it was visible to main, i.e. declared before it or forward declared. SilverShalkin wrote: wouldnt this work... what am i forgetting... i keep getting a undeclared identities thing. You can only call this function on a student, there is no global function of this name. If you made the function static, you could call it on Student itself, otherwise you need to create a student and call the method. Student s; s.SetName("a") // You allowed a char, which is one character Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

      N S 2 Replies Last reply
      0
      • C Christian Graus

        Yeah, but at least I spotted why he couldn't access the function.... Seriously, you're right, of course. *blush* Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #7

        Christian Graus wrote: Yeah, but at least I spotted why he couldn't access the function.... No points for that:) The guy already knew that

        C 1 Reply Last reply
        0
        • R Rama Krishna Vavilala

          Christian Graus wrote: Yeah, but at least I spotted why he couldn't access the function.... No points for that:) The guy already knew that

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #8

          Then why did he ask: wouldnt this work... what am i forgetting... i keep getting a undeclared identities thing. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

          1 Reply Last reply
          0
          • C Christian Graus

            Yeah, but at least I spotted why he couldn't access the function.... Seriously, you're right, of course. *blush* Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #9

            The funny thing is that it might have worked for the guy if he casted it and he'd have used it without realizing it was a typo error Nish


            Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

            N 1 Reply Last reply
            0
            • N Nish Nishant

              The funny thing is that it might have worked for the guy if he casted it and he'd have used it without realizing it was a typo error Nish


              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #10

              Blast. My bad!!! He'd have been casting the pointer address to char :( Nish


              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

              1 Reply Last reply
              0
              • C Christian Graus

                SilverShalkin wrote: voide SetName(char Name) { } correct? A global function, yes. SilverShalkin wrote: int main() { SetName("Judy") return 0; } So long as it was visible to main, i.e. declared before it or forward declared. SilverShalkin wrote: wouldnt this work... what am i forgetting... i keep getting a undeclared identities thing. You can only call this function on a student, there is no global function of this name. If you made the function static, you could call it on Student itself, otherwise you need to create a student and call the method. Student s; s.SetName("a") // You allowed a char, which is one character Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

                S Offline
                S Offline
                SilverShalkin
                wrote on last edited by
                #11

                Christian Graus wrote: Student s; s.SetName("a") // You allowed a char, which is one character I was thinking that.. the only problem is that the student... Student s i will always keep adding students.. could i make s an array? that always changes? like: Student s[nextname]; ? Thanks All ~SilverShalkin :rose:

                C 1 Reply Last reply
                0
                • S SilverShalkin

                  Christian Graus wrote: Student s; s.SetName("a") // You allowed a char, which is one character I was thinking that.. the only problem is that the student... Student s i will always keep adding students.. could i make s an array? that always changes? like: Student s[nextname]; ? Thanks All ~SilverShalkin :rose:

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #12

                  No, you cannot do that - you can make an array of students ( or better yet, a std::vector ). That would be the point - each student knows what it's name is. To make s an array you would put Student [12] s; ( from memory ) Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

                  S 1 Reply Last reply
                  0
                  • C Christian Graus

                    No, you cannot do that - you can make an array of students ( or better yet, a std::vector ). That would be the point - each student knows what it's name is. To make s an array you would put Student [12] s; ( from memory ) Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

                    S Offline
                    S Offline
                    SilverShalkin
                    wrote on last edited by
                    #13

                    Christian Graus wrote: Student [12] s; why is the [12] behind s? And so i wouldnt beable to make the [12] into somthing that increases everytime you call it? oh,... this project is a learning project... its not ment to go the easy path or anything, its ment for me to understand the class and using header. there is a couple other ways i probably could do this "me" you know, the guy that know the least on this forum... :) thanks again! c-ya ~SilverShalkin :rose:

                    C 1 Reply Last reply
                    0
                    • S SilverShalkin

                      Christian Graus wrote: Student [12] s; why is the [12] behind s? And so i wouldnt beable to make the [12] into somthing that increases everytime you call it? oh,... this project is a learning project... its not ment to go the easy path or anything, its ment for me to understand the class and using header. there is a couple other ways i probably could do this "me" you know, the guy that know the least on this forum... :) thanks again! c-ya ~SilverShalkin :rose:

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #14

                      SilverShalkin wrote: why is the [12] behind s? And so i wouldnt beable to make the [12] into somthing that increases everytime you call it? Read my first STL article, on vector. That's what you need to have a dynamic array. SilverShalkin wrote: oh,... this project is a learning project... its not ment to go the easy path or anything, its ment for me to understand the class and using header. there is a couple other ways i probably could do this "me" you know, the guy that know the least on this forum... I applaud you for taking this on, I'm sure you'll learn a lot from it. Just keep the questions coming.... Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

                      1 Reply Last reply
                      0
                      • R Rama Krishna Vavilala

                        Use the correct decl. void Student::SetName(char* Name); { }

                        P Offline
                        P Offline
                        Paul M Watt
                        wrote on last edited by
                        #15

                        Rama Krishna wrote: void Student::SetName(char* Name); { } You would actually need to remove the semicolon: void Student::SetName(char* Name) { }


                        Build a man a fire, and he will be warm for a day
                        Light a man on fire, and he will be warm for the rest of his life!

                        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