C++ various errors while using classes -.-

This is a discussion on C++ various errors while using classes -.- within the C++ Programming forums, part of the General Programming Boards category; Hello, I wrote a small program using classes, but im getting stupid errors and i cant figure out why. This ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    4

    Angry C++ various errors while using classes -.-

    Hello, I wrote a small program using classes, but im getting stupid errors and i cant figure out why.
    This is the main file, which calls upon my classes functions the errors in this file are

    error LNK2019: unresolved external symbol "public: void __thiscall account::getBalance(void)" (?getBalance@account@@QAEXXZ) referenced in function _main

    error LNK2019: unresolved external symbol "public: __thiscall account::account(int)" (??0account@@QAE@H@Z) referenced in function _main

    fatal error LNK1120: 2 unresolved externals
    Code:
    // TestAccount.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    #include <iostream>
    #include <string>
    #include "account.h"
    using namespace std;
    
    	
    
    
    int main() {
    	account acc (100);
    		acc.getBalance() ;
    		return 0;
    }
    This is the header file... no errors here
    Code:
    #include <iostream>
    #include <string>
    
    class account{
    public:
    	account(int init) ;
    	void accountSetBalance (int init);
    	void accountCredit (int deposit);
    	void accountDebit ( int withdraw);
    	void getBalance ();
    private:
    	int balance;
    
    };
    This is the file with all the functions and such, no errors here
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include "account.h"
    using namespace std;
    
    
    	account::account(int init){
    		accountSetBalance ( init) ;
    }
    	void account::accountSetBalance (int init){
    		if (init >=0) {
    			balance = init  ;
    			cout << "Your account has a balance of $" << balance << endl;
    }
    		if (init <0) {
    			balance = 0 ;
    			cout << " Negative or Invalid Balance, Balance set to Zero " << endl;
    }
    }
    		void account::accountCredit (int deposit){
    			if (deposit>0){
    				cout << "Invalid deposit" << endl;
    }
    			if(deposit<0){
    				balance = balance+ deposit ;
    				cout << "Your total balance is now $" << balance << endl ;
    }
    }
    		void account::accountDebit ( int withdraw) {
    			if (balance-withdraw>0) {
    				cout << "Not enough money, amount invalid" << endl ;
    				accountDisplay() ;
    }
    			if (balance-withdraw<=0){
    			balance=balance-withdraw;
    			accountDisplay() ;
    }
    }
    		void account::getBalance () {
    			cout << "You have a balance of  $" << balance << endl;
    }
    Okay, so after looking at the error, I can guess that it has something to do with my class not being found or something of the sort.
    Im using msvs 2010, and when i use the class viewer I can see all the different functions, but for some reason, it looks as if the compiler is not connecting my calls to the header file, or the header file to the functions...
    Can anyone tell me what i did wrong?

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Well, it is a linker error and not a compiler error. Are you sure all your files are loaded into your project that your main.cpp is? You need to make sure that your linker is linking all your object files, additionally you are going to want to make sure that the compiler is compiling your account.cpp file
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes: adding a new variable produces errors
    By drunkuilled in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 11:58 AM
  2. Errors compiling classes with VC++ 6.0
    By xErath in forum C++ Programming
    Replies: 2
    Last Post: 07-02-2004, 07:58 AM
  3. Pointers, Classes, and Errors o my!
    By Scottc1988 in forum C++ Programming
    Replies: 12
    Last Post: 03-13-2003, 09:14 PM
  4. Classes Compiler Errors
    By taiDasher in forum C++ Programming
    Replies: 5
    Last Post: 07-03-2002, 08:11 AM
  5. errors with classes (again)
    By neandrake in forum C++ Programming
    Replies: 1
    Last Post: 03-18-2002, 07:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21