0

This is the weirdest problem I have ever encountered, everything is correct and has been reviewed closely and the program still does not run. I tried this code on an online IDE as well (zybooks; my university's curriculum) and it worked perfectly fine on there.

What am I doing wrong?

main.cpp

#include <iostream>

#include "Character.h"

using namespace std;

int main(){
    Character character("ekko", "black", 100, 100);
    cout << character.getName();

    return 0;
}

Character.cpp

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

Character::Character(){
    name = "Summoner";
    race = "NONRACIAL";
    level = 0;
    health = 0;
}

Character::Character(string name, string race, int level, int heatlh ){
    this->name = name;
    this->race = race;
    this->level = level;
    this->health = health;
}

void Character::setName(string name){ this->name = name; }
void Character::setRace(string race){ this->race = race; }
void Character::setLevel(int level){ this->level = level; }
void Character::setHealth(int health){ this->health = health; }

string Character::getName(){ return name; }
string Character:: getRace(){ return race; } 
int Character:: getLevel(){ return level; }
int Character:: getHealth(){ return health; }

Character.h

#include <iostream>

using namespace std;

#ifndef CHARACTER_H
#define CHARACTER_H

class Character{
private:
    string name;
    string race;
    int level, health;

      
public:
    Character();
    Character(string name, string race, int level, int heatlh );

    string getName();
    string getRace(); 
    int getLevel();
    int getHealth();

    void setName(string name);
    void setRace(string race);
    void setLevel(int level);
    void setHealth(int health);
};

#endif

Error:

[Running] cd "c:\Users\diono\OneDrive\Desktop\COSC_1430_RPG_GAME\Character\" && g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile && "c:\Users\diono\OneDrive\Desktop\COSC_1430_RPG_GAME\Character\"tempCodeRunnerFile
c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
C:\temp\gcc\build-mingw-w64\mingw-w64-crt/../../src/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status

[Done] exited with code=1 in 0.883 seconds
halfer
  • 19,824
  • 17
  • 99
  • 186
Dion
  • 9
  • 3
  • `g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile` main.cpp is missing. No tempCodeRunnerFile.cpp in the question. – 273K Apr 09 '21 at 00:07
  • 2
    You may want to switch away from using code runner and read the documentation on how to modify tasks.json to build all of your source files: [https://code.visualstudio.com/docs/cpp/config-mingw](https://code.visualstudio.com/docs/cpp/config-mingw) – drescherjm Apr 09 '21 at 00:25
  • I'd recommend a build system over modifying tasks.json, but that's obviously subjective. – sweenish Apr 09 '21 at 00:42

1 Answers1

0

Visual Studio Code just is Editor Coding Environment, so you need to add more compile tools for it such as Cmake to execute your code. https://code.visualstudio.com/docs/cpp/cmake-linux#:~:text=Install%20the%20C%2FC%2B%2B%20extension,a%20debugger%2C%20and%20build%20tools.