Thread: c++ -- returning an array from function

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You really should get a book.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #17
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Quote Originally Posted by cpjust View Post
    What array? You're passing a single char by value to the function.
    This is how you pass an array by reference:
    Code:
    void start_rubik( char*** cube )
    or
    void start_rubik( char cube[6][3][3] )
    lol... sorry, stupid mistake

  3. #18
    Registered User
    Join Date
    Aug 2008
    Posts
    14
    ok i came to the conclusion for now this project is officially being scraped, i am running into thousands of problems....especially once i start trying to make a function to turn the cube...I will need to look for something a bit simpler perhaps.

  4. #19
    Registered User
    Join Date
    Aug 2008
    Posts
    14
    Quote Originally Posted by King Mir View Post
    You really should get a book.
    my parents will not buy me one....I went to library they had like 6 million books on PHP but i am already very good with php so thats not what i need... for now i will need to stick to the internet.

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Take a look at our book recommendation thread. For novices I would point out Accelerated C++ - check if it is hiding among the many PHP books in your local library.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    other languages like php are able to return arrays and it is written in c++ i just figured it would be possible...
    They are completely different languages. There are things that can be done in one and not in the other, or at least as easily.

    In this particular case, though, it is possible. A PHP array is more like a std::vector in C++. A C++ array is a lot more primitive. It is essentially just a continuous block in memory, and doesn't know about it's own length and such.

  7. #22
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    I know I will be disagreeing with many people here by saying this, but I find the internet just as helpful as books given you find the right tutorials written by people who know what they are doing. I have never read a book on C++. Not saying I know much about C++, I don't. But I think I do know enough to know how to Google for specific topics that I need. For instance, I was doing SDL a while ago, and had done a few simple games. I am currently learning Qt, and can follow through the tutorials quite comfortably, knowing what I am doing at each stage. I do have a (what I think is) weird way of following through tutorials, though - I read through the section once, see the end result, and close everything except my editor and a command prompt for compilation, and try to reimplement what I just saw, myself, from scratch. And then I would compare my code to the tutorial code, and ponder on the differences. I think it's quite effective.

    That said, I seem to have an endless supply of passion for programming, so I can and do spend A LOT of time on it, mostly on Google.

  8. #23
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    There are a few books available online.
    Try here or this.

    I haven't read these books myself, so I can't vouch for their quality.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  9. #24
    Registered User
    Join Date
    Aug 2008
    Posts
    14
    well, once again thanks for the input, I will be keeping my eyes out for the books...i may grab a e book of c++ to read....*pops google up*

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    Take a look at our book recommendation thread. For novices I would point out Accelerated C++ - check if it is hiding among the many PHP books in your local library.
    Also, most libraries allow cross-lending from one library to another, so if you ASK the staff nicely to look up this book:
    Accelerated C++: Practical Programming by Example
    by Andrew Koenig (Author), Barbara E. Moo (Author)
    ISBN: 020170353X
    If they can't locate it, perhaps you can find a university library or some such that can lend it to you?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I will need to look for something a bit simpler perhaps.

    void start_rubik( char cube[6][3][3] )

    That solution is simple and is probably the best one for this problem anyway. Hopefully you will learn about dynamic memory later in your C++ studies, but I don't think there's any reason to use new/delete here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 6
    Last Post: 10-21-2003, 09:57 PM