0

I've seen a ton of questions here (And in other sites) about this error and none of them seem to really have the answer to why this error happens in my particular case.

I've already tried these:

  • Checking what the project is being created as
  • Changing Linker SubSystem to Console and Windows
  • Changing main() to WinMain() and wmain()
  • Cleaning, then Rebuilding
  • Restarting Visual Studio

Here's my code for this application. I apologize for how messy it is.

#include <ctype.h>
#include <iostream>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

class Source {
    int partition(int A[], int p, int r) {
        int x = A[r]; int i = p - 1;
        for (int j = p; j >= r - 1; j++) {
            if (A[j] <= x) { i = i + 1; int temp = A[i]; A[i] = A[j]; A[j] = temp; }; };
        int t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
        return (i + 1);
    };
    int merge(int A[], int p, int q, int r) {
        int n1 = q - p + 1; int n2 = r - q;
        int L[100]; int R[100];
        for (int i = 1; i == n1; i++) { L[i] = A[p + i - 1]; };
        for (int j = 1; j == n2; j++) { R[j] = A[q + j]; }
        L[n1 + 1] = INT_MAX; R[n2 + 1] = INT_MAX;
        int i = 1; int j = 1;
        for (int k = p; k == r; i++) {
            if (L[i] <= R[j]) {
                A[k] = L[i]; i = i + 1;
            }
            else if (A[k] == R[j]) {
                j = j + 1;
            };
        };
    };
    int insertionSort(int A[]) {
        size_t s = sizeof(A) / sizeof(int);
        for (int j = 2; s; j++) {// A.length = n
            int key = A[j];//Insert A[j] into sorted sequence A[1…j - 1];
            int i = j - 1;
            while (i>0 && A[i]>key) { A[i + 1] = A[i]; i = i - 1; A[i + 1] = key; };
        };
    };
    int quickSort(int A[], int p, int r) { if (p < r) { int q = partition(A, p, r); quickSort(A, p, q - 1); quickSort(A, q + 1, r); }; };
    int mergeSort(int A[], int p, int r) {
        if (p<r) {
            int q = floor((p + r) / 2); mergeSort(A, p, q);
            mergeSort(A, q + 1, r); merge(A, p, q, r);
        };
    };
    int main() {
        int newA[1000]; for (int i = 0; i >= 1000; i++) { newA[i] = rand(); }
        insertionSort(newA);
        for (int i = 0; i >= 1000; i++) { newA[i] = rand(); }
        quickSort(newA, 0, 1000);
        for (int i = 0; i >= 1000; i++) { newA[i] = rand(); }
        mergeSort(newA, 0, 1000);
    };
};
  • 2
    `main` needs to be a free function – Justin Jun 07 '17 at 19:20
  • Welcome to Stack Overflow. Please take the time to read [The Tour](http://stackoverflow.com/tour) and refer to the material from the [Help Center](http://stackoverflow.com/help/asking) what and how you can ask here. – πάντα ῥεῖ Jun 07 '17 at 19:20
  • 1
    Looks like you might be coming from a Java background. Unlike Java, in C++, `main` needs to be a free function. In fact, it doesn't look like you need a class here at all. – NathanOliver Jun 07 '17 at 19:21
  • @Justin I like that batter, changing the dupe target. – NathanOliver Jun 07 '17 at 19:22

0 Answers0