mental walkthrough

This is a discussion on mental walkthrough within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I was just wondering how I should mentally approach (like steps to take) creating a function...especially class member ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    153

    mental walkthrough

    Hey everyone,
    I was just wondering how I should mentally approach (like steps to take) creating a function...especially class member functions...I'm reading this book and the author created an assignment operator function....and I understand what it does, but whenever I try and do something similar on my own, my mind goes blank and I'm like...uhhh, allocate memory...uhhh...haha, I probably sound like an acehole but what can ya do? Well anyways I was wondering if anyone had any pointers (no pun intended, hahaha) and whatnot...thanks a lot. - Chap

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    All I can think to suggest is that you remember what purpose the function is intended to serve and how it needs to do it. With your example of an assignment operator, you should be considering what elements of the object require modification as a result of the assignment. If, for example, you have a string class that allocates heap to store data and you assign something to it, depending on your implementation, first you might want to check if your allocation is large enough to hold the assigned text and if not, reallocate, then set your member that stores the length of the string and assign each byte to your memory.

    It's kind of hard for me to verbalize to someone else how they should think about thinking about doing something, but hopefully my comments will be of some assistance (as little as it may be).

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Nice pun, by the way.

    Try do a flow chart. Just start somewhere where you know your program has to be at some point, even if it's not at the beginning. Now think, "Do I need to declare data before this?", "Any other setup routines?", "How do I clean up?", "Where do I go next?", etc...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Peasant's Quest Walkthrough
    By sean in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-25-2004, 06:46 AM
  2. AAARG!!! mental block, what is this character called: ')'
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-29-2002, 09:29 PM
  3. going mental - autorecovery system
    By iain in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2001, 06:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21