0

I'm new to c++ classes and I'm practicing in vs code, here is the output in terminal

C:\Users\Sainath\Desktop\Classes>cl main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30139 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 14.29.30139.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
main.obj
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Account::set(double)" (?set@Account@@QAEXN@Z) referenced in function _main
main.exe : fatal error LNK1120: 1 unresolved externals 


Main.cpp


#include <iostream>
#include "Account.h"
using namespace std;

int main()
{
    Account ram;
    ram.set(200.00);
}


Account.h


#pragma once
class Account
{
private:
    double balance;

public:
    void set(double bal);
    double get();
};

Account.cpp

#include "Account.h"

void Account::set(double bal)
{
    balance = bal;
}

I've observed that if I remove the Account.cpp and define the methods in main.cpp itself it doesn't throw back an error
what should I do in order for the program to run without any errors?

0 Answers0