-4
int year;
int month;
int day;

ADate * date = new ADate(year, month, day);

I know it's usually used for pointers but I don't know what it's doing here. Without it that line obviously creates a new ADate with those int variables passed in but I'm not sure what the * does that changes this?

Alex
  • 419
  • 6
  • 24
  • 1
    just a pointer constructed by the new AData. – Max Jan 16 '17 at 19:13
  • 4
    BTW, you don't need to use `operator new` to create variables in C++. C++ is not Java and not C#. – Thomas Matthews Jan 16 '17 at 19:14
  • Yes, it is usually used for pointers, and this case is no exception. Without it that line won't even compile. – bereal Jan 16 '17 at 19:14
  • you are declaring a pointer of type cladd aDate and initializing it on the heap. if you remove it then you are declaring an object of class aDate but you must remove keyword new – Raindrop7 Jan 16 '17 at 19:16
  • @jaggedSpire I looked online for some info regarding it but unfortunately the first 5 pages are all about pointers. – Alex Jan 16 '17 at 19:18
  • 1
    The `*` is part of the [pointer declarator](http://en.cppreference.com/w/cpp/language/pointer). – wally Jan 16 '17 at 19:20
  • [This](http://stackoverflow.com/q/6990726/1460794) might be relevant. – wally Jan 16 '17 at 19:21

1 Answers1

1

With the *, date is declared as a pointer type, which stores the address of a ADate object (points to a ADate object). Otherwise, date would be declared as a ADate object type.

The operator new returns a pointer. Thus without the *, your program wouldn't be successfully compiled.

http://www.cplusplus.com/reference/new/operator%20new/

immiao
  • 102
  • 9