c++ class why need main?

后端 未结 5 2125
难免孤独
难免孤独 2021-01-27 01:28

Hello I\'m writing a little project in c++ where I would like to have some classes that does some work, I wrote the interfaces and the implementation of the classes.

The

5条回答
  •  野性不改
    2021-01-27 01:52

    First, this is wrong: animal dog = new animal();

    You either need

    animal * dog = new animal();
    cout << dog->method1(42);
    delete animal;
    

    or preferably just

    animal dog;
    

    Second, you need to link together the object files produced by compiling your two source .cpp files.

    gcc -o animal animal.cpp app.cpp 
    

    should do the trick, if you're using gcc.

提交回复
热议问题