Thread: Need help with fuctions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Yes, if it doesn't need to return anything, then don't return anything; make it void. No sense in returning a value which has no meaning whatsoever.

    And be careful about adopting a policy in which functions return errors. In some cases, all possible return values could be validly returned. An example: you have a function that does some number crunching and returns an integer, but any integer it could return is valid (so, you can't say, "well, if it returns -1 (for example), then it failed"). There are ways to get around this, and get multiple output values from a function (not return multiple values, but there are other ways to have values output). Additionally, there are other mechanisms for error handling (exceptions are one example built right into the language; other user defined error reporting mechanisms can also be devised).
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  2. #2
    Registered User stillwell's Avatar
    Join Date
    Aug 2004
    Posts
    80
    I need some more help.

    I'm trying to make my own header file, but I'm having some trouble. I have placed the .cpp file and the .h file in different directories, and have linked to those directories in my project....but when I compile it, it gives the message: Undefined reference to `nl(int)'

    Here are my 3 files.

    simplestuff.ccp:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include "simplestuff.h"
    
    using namespace std;
    
    void nl(int i)
    {
    int t = 1;
    
    while (i >= t)
          {
          cout << t << endl;
          t++; 
          }
    }
    simplestuff.h:

    Code:
    void nl(int i);
    nl_test.cpp:

    Code:
    #include <cstdlib>
    #include <iostream>
    #include "simplestuff.h"
    
    using namespace std;
    
    int main()
    {
        
    cout << "Hey";
    nl(5);
    cout << "Der";    
        
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vectors and fuctions
    By mixalissen in forum C++ Programming
    Replies: 13
    Last Post: 05-05-2008, 11:48 AM
  2. Problem with cos, sin fuctions
    By xxxhunter in forum C Programming
    Replies: 7
    Last Post: 11-16-2007, 03:33 AM
  3. Quad equation using fuctions problem
    By godfrey270487 in forum C++ Programming
    Replies: 5
    Last Post: 12-07-2006, 11:23 AM
  4. 2 fuctions please
    By dac in forum C++ Programming
    Replies: 3
    Last Post: 02-13-2006, 05:55 AM
  5. Replies: 8
    Last Post: 04-11-2004, 11:19 PM