-1

I am new to C++, but I do pretty well at C# and Java. I am trying to do some basic exercise here:

// HelloWorld.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

bool isSame(int[] pFirst, int[] pSecond, int pLength) {

}

int _tmain(int argc, _TCHAR* argv[])
{


    return 0;
}

That is my entire file, but VC++ (I am using VS 2013) keeps complaining:

1   IntelliSense: expected a ')'

at the isSame declaration line.

What do I do wrong? I am writing a function to compare if two arrays are containing the same values, and here is the solution:

bool ArrayEq( int A1[], int A2[], int size ) {
  for (int k=0; k<size; k++) {
    if (A1[k] != A2[k]) return false;
  }
  return true;
}
Luke Vo
  • 17,859
  • 21
  • 105
  • 181
  • 3
    In addition to the answer below: Don´t get used to "using namespace" and "TCHAR", "_tmain" in the first place. – deviantfan Jun 28 '14 at 10:12
  • 1
    @deviantfan thank you. For anyone who comes later, this explains why you shouldn't use it: http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice – Luke Vo Jun 28 '14 at 10:20

1 Answers1

3

The correct syntax would be int pFirst[].

But first of all this function already exists in the standard library, and second std::vector overloads operator ==.

Both should be prefered over handcrafted code and std::vector is better than a C-style array.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
  • Thanks for the info :) I am new and feeling so many things to learn. That was precious information. – Luke Vo Jun 28 '14 at 10:15