function problems

This is a discussion on function problems within the C++ Programming forums, part of the General Programming Boards category; alright, i have a function declared as void, and what it does, it prints stuff out to the screen, now ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    function problems

    alright, i have a function declared as void, and what it does, it prints stuff out to the screen, now whenever i call this function, i get this error:
    implicit declaration of function `int swap(...)'

    what the hell does that mean? i copied it directly out of my book

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    post the code.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    7
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    int x = 5, y=10;
    cout <<"Main. Before swap, x: " <<x<<" y: "<< y<< "\n";
    swap(x,y);
    cout <<"Main. After swap, x: "<<x<<" y: "<<y <<"\n";
    return 0;
    }
    
    void swap(int x, int y){
    int temp;
        cout "Swap. Before swap, x: " << x << " y: "<< y<< "\n";
    
        temp = x;
        x = y;
        y = temp;
    
        cout << "Swap. After swap, x: "<<x<<" y: "<<y<< "\n";
    
    }

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You are using a function before it has been declared. Above main add this line.....

    void swap(int,int);

    This is called a function prototype and tells the compiler the functions return type and parameter list.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    You can also place the function before main() but with too many functions this can get ugly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM
  5. Problems with str.replace function
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 03:35 AM

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