Wow I screwed up big in C++

Discussion in 'Programming' started by Xphic, Mar 27, 2008.

  1. #1
    What did I do wrong? it's most likely a couple of errors making 65 errors

    cc.h file

    
    class CreditCard
    {
    public:
    	char group;
    	int id;
    	double balance;
    	double creditLimit;
    
    	double getBalance();
    	double getcreditLimit();
    	int getID();
    	char getgroup();
    
    	double setBalance(double B);
    	double setcreditLimit(double CL);
    	int setID(int ID);
    	char setGroup(char G);
    
    	void Display();
    
    };
    
    Code (markup):

    cc.cpp
    
    
    #include <iostream>
    #include "cc.h"
    #include "creditcard.cpp"
    using namespace std ;
    
    void main()
    {
    	CreditCard cc1, cc2, cc3;
    
    	cc1.setBalance(300.00);
    	cc1.setcreditLimit(400.00);
    	cc1.setGroup('A');
    	cc1.setID(14);
    
    	cc2.setBalance(400.00);
    	cc2.setcreditLimit(600.00);
    	cc2.setGroup('B');
    	cc2.setID(17);
    
    	cc3.setBalance(1000.00);
    	cc3.setcreditLimit(1000.00);
    	cc3.setGroup('C');
    	cc3.setID(18);
    }
    
    Code (markup):
    creditcard.cpp
    //------------------- MACHINE.CPP -------------------
    
    // This file contains definitions of member functions for the classes
    // CoinCounter, Dispenser, and SodaMachine
    
    #include <iostream>
    #include "cc.h"
    using namespace std ;
    
    //------------------- CoinCounter Definitions
    
    double CreditCard::getBalance()
    {
    	return balance;
    }
    
    double CreditCard::getcreditLimit()
    {
    	return creditLimit;
    }
    
    int CreditCard::getID()
    {
    	return id;
    }
    
    char CreditCard::getgroup()
    {
    	return group;
    }
    
    void CreditCard::setBalance(double B)
    {
    	balance = B;
    }
    
    void CreditCard::setID(int ID)
    {
    	id = ID;
    }
    
    void CreditCard::setcreditLimit(double CL)
    {
    	creditLimit = CL;
    }
    
    void CreditCard::setGroup(char G)
    {
    	group = G;
    }
    
    CreditCard::Display()
    {
    	cout << endl;
    	cout <<"Group " << group << endl;
    	cout <<"ID: " << id << endl;
    	cout <<"Balance: " << balance << endl;
    	cout <<"Credit Limit " << creditLimit << endl;
    }
    Code (markup):
     
    Xphic, Mar 27, 2008 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well... it would help if you actually copied the errors here, too. A lot of us don't have easy access to compilers but can still work stuff out from errors.

    I daresay, though, that one of your problems is that you are including cc.h twice by way of including cc.h and creditcard.cpp (which includes cc.h again) in cc.cpp.

    For what it's worth, you're not really meant to include cpp files, either. I mean it may work (I haven't used it in a while), but it's bad form.
     
    TwistMyArm, Mar 27, 2008 IP
    Xphic likes this.
  3. Xphic

    Xphic Active Member

    Messages:
    1,323
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    80
    #3
    thanks twist it lowered it to 23 errors

    and found some stuff, now down to three errors

    edit again


    Now I have two errors left

    1>cc.obj : error LNK2019: unresolved external symbol "public: __thiscall CreditCard::CreditCard(void)" (??0CreditCard@@QAE@XZ) referenced in function _main
    1>C:\Documents and Settings\cim208\My Documents\Visual Studio 2005\Projects\cc\Debug\cc.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Documents and Settings\cim208\My Documents\Visual Studio 2005\Projects\cc\cc\Debug\BuildLog.htm"
     
    Xphic, Mar 27, 2008 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK, so I assume you removed the include of the CPP file, right?

    I assume what's happening now is that you've not compiled the creditcard.cpp file. You need to compile cc.cpp and creditcard.cpp separately, and then the linker should combine the two to create the final EXE.
     
    TwistMyArm, Mar 27, 2008 IP
  5. Xphic

    Xphic Active Member

    Messages:
    1,323
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    80
    #5
    it's fixed, and yeah I tried that it didn't work for me.

    The problem was it wouldn't automatically create a constructor for me, so I had to add one in the cpp file not just the header
     
    Xphic, Mar 27, 2008 IP