what would be the correct syntax and how would i run this? - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24

Thread: what would be the correct syntax and how would i run this?

  1. #16
    Join Date
    Apr 1999
    Posts
    27,424

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by theunknowncoder View Post
    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

  2. #17
    Join Date
    Oct 2012
    Posts
    18

    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

  3. #18
    Join Date
    Oct 2012
    Posts
    18

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by Paul McKenzie View Post
    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

  4. #19
    Join Date
    Apr 1999
    Posts
    27,424

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by theunknowncoder View Post
    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

  5. #20
    Join Date
    Oct 2012
    Posts
    18

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by Paul McKenzie View Post
    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

  6. #21
    Join Date
    Apr 1999
    Posts
    27,424

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by theunknowncoder View Post
    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

  7. #22
    Join Date
    Oct 2012
    Posts
    18

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by Paul McKenzie View Post
    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 ?

  8. #23
    Join Date
    Apr 1999
    Posts
    27,424

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by theunknowncoder View Post
    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.

  9. #24
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,068

    Re: what would be the correct syntax and how would i run this?

    Quote Originally Posted by theunknowncoder View Post
    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center