lundi 2 octobre 2017

Can't assign a value to a variable inside a class

#include <iostream>

using namespace std;

class Foo {

    int i;
    int * p = new int;
    *p = 5; // This doesn't worl
    // If I instead use  int * p = new int(5); it works.
};

Why that? I see that this only occurs inside a class, if I write the same code on the main function it should work.

Aucun commentaire:

Enregistrer un commentaire