I got an error:
-Functions that differ only in their return type cannnot be overload (#8)
-Implicit conversion loses integer precision: "time_t'(aka "lomg") to unsigned int (#14)
-Implicit cnversion loses integer precision: long to int (#18)
-Functions that differ only in their return type cannnot be overload (#24)

#include  <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

void printEachIteration(int* , int );
void selectionSort(int* , int );
int random();

int main ()
    const int ArraySize = 100;
    int array[ArraySize];

    for (int i = 0; i < ArraySize + 1;i++)
        array[i] = random();

    selectionSort(array, ArraySize);
    return 0;
int random()
    return ((rand() % 100));

Recommended Answers

All 4 Replies

I think if you mention what compiler you use, might help someone who can properly answer your questions.

To me they don't look like errors at all, warnings perhaps, but then there might be more code you are not showing.

Sorry but you have steped into one of those nasty legacy areas from C.

There exists a function [in stdlilb.h which is included via cstdlib] long int random(). Thus the first of your errors.

To avoid this either (a) rename your functions e.g. random100 or something (b) give it an argument (e.g. random(const int N) (c) put it in a namespace.

Then we have the scary stuff:

You write

 for (int i = 0; i < ArraySize + 1;i++)
        array[i] = randomInt();

Hang on a second!! you only allocated ArraySize items for the array.... so now you are filling ArraySize+1 items. That is not good, and is corrupting memory!


Please stop putting using namespace std; at the top of your code!! Global things like random() left over from C, have been (slightly) mitigated by putting many things into the namespace std. So you have just pulled in about 2500 different names. Each one is waiting to cause a difficult to find bug. So if you want to use an item from namespace std. Either

(a) write stuff like this std::cout<<"This is some output"<<std::endl;
(b) Just get the bit you need e.g. put this code at the top
using std::cout; Obviously you need to add everything you are using e.g. endl etc...
(c) Put your using namespace std; in just small scopes (e.g. the function/method.

I prefer (a) over (b) over (c) ...but many will have a different order.

The random() function is a system function that returns a long int. You have declared that your random() function returns an int, and this is the cause of the compiler complaint. FWIW, long int random() is declared in <stdlib.h>.

I fix because random have same name as system have that why didnt like it. So i change the to somethese.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.