Function() question...
-
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:
-
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:
Use the correct decl. void Student::SetName(char* Name); { }
-
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:
You are passing a char* to a char. Change the char to char* in your function's argument list Nish
Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.
-
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
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.
-
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.
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
-
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:
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
-
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
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
-
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
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
-
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
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.
-
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.
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.
-
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
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:
-
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:
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
-
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
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:
-
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:
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
-
Use the correct decl. void Student::SetName(char* Name); { }
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!