-
October 7th, 2012, 08:36 PM
#16
Re: what would be the correct syntax and how would i run this?
Originally Posted by theunknowncoder
ok so i read up abit on c++ learnt it for about 5 hours
It takes weeks, months, and yes, sometimes years to be proficient in C++. You can't learn it in 5 hours. C++ is not HTML or some simple scripting language where all you need is a couple of hours and a cheat sheet helping you out.
Regards,
Paul McKenzie
-
October 7th, 2012, 08:37 PM
#17
Re: what would be the correct syntax and how would i run this?
i know how to do one to a variable but i cant find any how to do one to a function anywhere
-
October 7th, 2012, 08:40 PM
#18
Re: what would be the correct syntax and how would i run this?
Originally Posted by Paul McKenzie
It takes weeks, months, and yes, sometimes years to be proficient in C++. You can't learn it in 5 hours. C++ is not HTML or some simple scripting language where all you need is a couple of hours and a cheat sheet helping you out.
Regards,
Paul McKenzie
i am not saying it is not but i am trying to learn from the basics and i cant find out how to do a pointer to a function i am gunna carry on learning for months and stuff but i am covering the basics first and coding to help me
-
October 7th, 2012, 08:42 PM
#19
Re: what would be the correct syntax and how would i run this?
Originally Posted by theunknowncoder
can i ask how you do a pointer to a function?
It isn't a pointer to a function. The function requires addresses passed to it for the last two arguments. An address is the same as a pointer. So you declare a variable of type T, and then pass the address of that variable (meaning you're passing a T*). I won't go any further -- look up what the address-of operator (&) does.
Secondly, what if you do finally get this to build successfully. Are you going to have the ability to debug your program if there are runtime errors?
Regards,
Paul McKenzie
-
October 7th, 2012, 08:45 PM
#20
Re: what would be the correct syntax and how would i run this?
Originally Posted by Paul McKenzie
It isn't a pointer to a function. The function requires addresses passed to it for the last two arguments. An address is the same as a pointer. So you declare a variable of type T, and then pass the address of that variable (meaning you're passing a T*). I won't go any further -- look up what the address-of operator (&) does.
Secondly, what if you do finally get this to build successfully. Are you going to have the ability to debug your program if there are runtime errors?
Regards,
Paul McKenzie
1 i already know what & does it shows u the memory address and 2 maybe maybe not but still i will keep goin till i do lets face it to get this to run i have been working on it for 6 weeks
-
October 7th, 2012, 08:46 PM
#21
Re: what would be the correct syntax and how would i run this?
Originally Posted by theunknowncoder
i am not saying it is not but i am trying to learn from the basics and i cant find out how to do a pointer to a function i am gunna carry on learning for months and stuff but i am covering the basics first and coding to help me
You don't learn basics by trying to write programs like this. Where are the "Hello World" programs, or simple main() programs that demonstrate simple usage of pointers, functions, etc? Why are you even looking at functions such as the one you're trying to call? It's like trying to learn to play the piano by looking at something Listz or Chopin wrote.
Code:
void SomeFunction(int *p)
{
*p = 10;
}
int main()
{
int myP = 0;
SomeFunction( &p );
}
Why are you not practicing things like this first?
I think you're too enamored by trying to use advanced concepts because you want to have "cool" graphics. Instead you should be writing simple programs so that you know what you're doing.
Regards,
Paul McKenzie
-
October 7th, 2012, 08:49 PM
#22
Re: what would be the correct syntax and how would i run this?
Originally Posted by Paul McKenzie
You don't learn basics by trying to write programs like this. Where are the "Hello World" programs, or simple main() programs that demonstrate simple usage of pointers, functions, etc? Why are you even looking at functions such as the one you're trying to call? It's like trying to learn to play the piano by looking at something Listz or Chopin wrote.
Code:
void SomeFunction(int *p)
{
*p = 10;
}
int main()
{
int myP = 0;
SomeFunction( &p );
}
Why are you not practicing things like this first?
I think you're too enamored by trying to use advanced concepts because you want to have "cool" graphics. Instead you should be writing simple programs so that you know what you're doing.
Regards,
Paul McKenzie
no its because i find the beginning stuff too easy then i get to the hard stuff and dont know what i am doing but i am starting to get the hang of it but how would you do a pointer to a return ?
-
October 7th, 2012, 10:58 PM
#23
Re: what would be the correct syntax and how would i run this?
Originally Posted by theunknowncoder
no its because i find the beginning stuff too easy
Then explain the program I wrote above. It uses pointers in exactly the same way that the function you're having trouble with. If you know what that program does, then why are you having so much trouble with writing the code to call your function?
There is virtually no difference in the code I wrote, and the function you're trying to call. The function takes a pointer, and your mystery function also takes a pointer, the only difference being the data type. My code calls the SomeFunction() correctly, but you say you can't figure out the syntax to call your function. So the only conclusion is that you are not retaining what you've learned, or you never learned the "easy stuff" properly, or you're not using what you know and applying it to a real program.
The SomeFunction() description would be something like this:
SomeFunction( int *ptrInt )
Usage:
[in] ptrInt - integer value to set
Does that look familiar? It looks identical to the documentation to your function's arguments, with the one exception that the type is int. So replace my "int" with the type that your function wants to use.
Also, just because a program is small doesn't mean it's "easy". What do you mean by "easy"? Honestly, you need to learn the basics of C++, and not try and cherry-pick topics so that you can create some sort of GUI program. If there is a concept in C++ you don't understand, then write a simple program and test out the concept before you apply that concept to a larger program.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; October 8th, 2012 at 04:12 AM.
-
October 8th, 2012, 11:29 AM
#24
Re: what would be the correct syntax and how would i run this?
Originally Posted by theunknowncoder
no its because i find the beginning stuff too easy then i get to the hard stuff and dont know what i am doing but i am starting to get the hang of it but how would you do a pointer to a return ?
Regardless of whether you find it easy or not, you really need to learn it so that you don't get hung up on a function call for six weeks. As for "how would you to a pointer to a return?", that doesn't make any kind of sense.
We see this quite a bit here. People try to take short cuts and dive in way over their heads then come here for explanations. It's not that we're not willing to help, but it's frustrating when people ask questions that don't make sense or ask questions that they lack the foundation to understand the answer.
This is a complex language with many concepts and nuances that need to be mastered. There really are no short cuts, even if you're experienced in other languages.
Last edited by GCDEF; October 8th, 2012 at 11:31 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|