There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox format freezes freezing hard drive hardware hijackthis install internet internet explorer itunes keyboard laptop malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
What is an "implicit declaraion" error?


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
robert2513's Avatar
Senior Member with 185 posts.
 
Join Date: Jun 2003
Location: Planet Earth
Experience: Intermediate
28-Mar-2005, 11:24 PM #1
What is an "implicit declaraion" error?
Hi.

I am working on this program for my C++ class. The assignment is you have to take a list, and sort it three different ways: Reverse, opposite order of how the user entered the numbers, Normal, how the user put in the numbers, and Sorted, from least to greatest.

Well, I got most of it done but when I compile it, I get an "implicit declaration of function "int swap(...)" According to the compiler, its on line 95. I have looked at this line and the declaration of my function "swap" but cannot find a problem with it. What does this type of error usually mean? Can anyone see what I am missing?

Thanks


Code:
#include<iostream.h>

int main()
{

//Funtion Prototypes
// The "s" variable stands for size

   void normal(int norm_list[], int& s);
   void reverse (int rev_list[], int& s);
   void sort (int sort_list[], int& s);
   void swap (int& x, int& y);

//Decleaer Variables
//Size is for the size of the list and index is the location in the array

	int size, index;


//Ask user for size of the list

	cout << "Please enter the size of the list: " ;
	cin >> size;

//Decleare array list[]
//Also, for loop enters the list into the array

	int list[size];
	for (index=0; index <=  size-1; index++)
	     {
		   cout << "Please enter the next interger: ";
           cin >> list[index];
	     }

//Call to functions to sort the numbers
//Functions (in order): Reverse, Normal, Sort

    reverse (list, size);
	normal (list, size);
    sort (list, size);

//Program End

cout << endl;
return 0;

}


//Reverse Function

void reverse (int rev_list[], int& s)
     {
        int x;

        cout << "List in REVERSE order:\n\n";
        for (x = s-1; x >=0; x--)
            {
               cout << rev_list[x] << "\n";
            }
        cout << "\n\n";
     }


//Normal Function

void normal(int norm_list[], int& s)
     {
	   int x;

       cout << "List in NORMAL order (as user inputted it): \n\n";
       for (x=0; x <= s-1; x++)
           {
               cout << norm_list[x] << "\n";
           }
       cout << "\n\n";
     }

 
//Sort Function

void Sort(int sort_list[], int& s)
    {
       int pass, k, x;
       for (pass=1; pass < s; pass++)
           {
             for (k=0; k < s - 1; k++)
                  {
                      if (sort_list[k+1] < sort_list[k])
                         {
                            swap (sort_list[k], sort_list[k+1]);
                         }
                  }
           }
       
        cout << "List in SORTED order (from least to greatest): \n\n";
        for (x=0; x < s; x++)
             {
                cout << sort_list[x] << "\n";
             }
        cout << "\n\n";
     }


//Swap Function

void swap(int& x, int& y)
     {
        int temp;

        temp = x;
        x = y;
        y = temp;
     }
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
29-Mar-2005, 01:59 PM #2
The swap error was because you had void swap (int& x, int& y); inside main (along with the other ones).

Then, there was a little problem with your Sort function();

Here's a little cleanup. You can take it from there.

Code:
#include <iostream>

using namespace std;

void swap(int& x, int& y) {
    int temp = x;
    x = y;
    y = temp;
}

void reverse (int rev_list[], int& s) {
    cout << "List in REVERSE order:\n\n";
    for (int x = (s - 1); x >= 0; --x) {
        cout << rev_list[x] << "\n";
    }
    cout << "\n\n";
}

void normal(int norm_list[], int& s) {
    cout << "List in NORMAL order (as user inputted it): \n\n";
    for (int x= 0; x <= (s - 1); ++x) {
        cout << norm_list[x] << "\n";
    }
    cout << "\n\n";
}

void sort(int sort_list[], int& s) {
    for (int pass = 1; pass < s; ++pass) {
        for (int k = 0; k < (s - 1); ++k) {
            if (sort_list[ k + 1 ] < sort_list[k]) {
                swap (sort_list[k], sort_list[ k + 1 ]);
            }
        }
    }
    cout << "List in SORTED order (from least to greatest): \n\n";
    for (int x = 0; x < s; ++x) {
        cout << sort_list[x] << "\n";
    }
    cout << "\n\n";
}

int main() {
    cout << "Please enter the size of the list: " ;
    int size;
    cin >> size;
    int list[size];
    for (int i = 0; i < size; ++i) {
        cout << "Please enter the next interger: ";
        cin >> list[i];
    }
    reverse(list, size);
    normal(list, size);
    sort(list, size);
    cout << endl;
}
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:11 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.