d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Easy Syntax
12Next
Add Reply New Topic New Poll
Member
Posts: 18,191
Joined: May 31 2010
Gold: 149.27
Sep 21 2014 03:51pm
// Kolten Minix - Co127 - 9/21/14
#include <iostream>
#include "baccount.h"
using namespace std;

int main(){
string name;
double start, amount;

cout << "Account Name: ";
cin >> name;

cout << "Initial Amount";
cin >> start;

//bank accounts constructor
bankAccount one(name, start);
cout << "deposit: ";
cin >> amount;
one.deposit(amount);

cout << "withdraw: ";
cin >> amount;
one.withdraw(amount);

cout << "Balance for " << one.name << "is " << one.balance() << endl;

}

complier returns:


Error 1 error C3867: 'bankAccount::name': function call missing argument list; use '&bankAccount::name' to create a pointer to member c:\users\kolt\documents\visual studio 2013\projects\final_balance\final_balance.cpp 26 1 final_balance



Pretty sure im using the name operartor wrong, if anyone has helpful advice on this syntax I would appreciate it
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 21 2014 03:55pm
1) please use code tags

2) one.name what is bankAccount::name? If it is a function then you ought to call it using parens: one.name()
Member
Posts: 18,191
Joined: May 31 2010
Gold: 149.27
Sep 21 2014 03:57pm
Sorry, okay I changed my code to;


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

int main(){
string name;
double start, amount;

cout << "Account Name: ";
cin >> name;

cout << "Initial Amount";
cin >> start;

//bank accounts constructor
bankAccount one(name, start);
cout << "deposit: ";
cin >> amount;
one.deposit(amount);

cout << "withdraw: ";
cin >> amount;
one.withdraw(amount);

cout << "Balance for " << one.name << "is " << one.balance() << endl;


but when I do that it brings up all this shit in my compiler

Code
Error 1 error LNK2019: unresolved external symbol "public: __thiscall bankAccount::bankAccount(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double)" (??0bankAccount@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@Z) referenced in function _main c:\Users\Kolt\documents\visual studio 2013\Projects\final_balance\final_balance.obj final_balance

Error 2 error LNK2019: unresolved external symbol "public: void __thiscall bankAccount::deposit(double)" (?deposit@bankAccount@@QAEXN@Z) referenced in function _main c:\Users\Kolt\documents\visual studio 2013\Projects\final_balance\final_balance.obj final_balance

Error 3 error LNK2019: unresolved external symbol "public: void __thiscall bankAccount::withdraw(double)" (?withdraw@bankAccount@@QAEXN@Z) referenced in function _main c:\Users\Kolt\documents\visual studio 2013\Projects\final_balance\final_balance.obj final_balance

Error 4 error LNK2019: unresolved external symbol "public: double __thiscall bankAccount::balance(void)const " (?balance@bankAccount@@QBENXZ) referenced in function _main c:\Users\Kolt\documents\visual studio 2013\Projects\final_balance\final_balance.obj final_balance

Error 5 error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall bankAccount::name(void)const " (?name@bankAccount@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main c:\Users\Kolt\documents\visual studio 2013\Projects\final_balance\final_balance.obj final_balance

Error 6 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup c:\Users\Kolt\documents\visual studio 2013\Projects\final_balance\MSVCRTD.lib(crtexew.obj) final_balance

Error 7 error LNK1120: 6 unresolved externals c:\users\kolt\documents\visual studio 2013\Projects\final_balance\Debug\final_balance.exe final_balance
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 21 2014 04:00pm
It looks like your project settings are wrong.

Are you sure you added all the .cpp files to the solution?

Are you using precompiled headers? If not, make sure they're set to off in project settings.

Are you using incremental linking? I remember having lots of issues with it back when I was forced to use msvc.

This post was edited by KrzaQ2 on Sep 21 2014 04:01pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Sep 21 2014 04:35pm
Would help if you posted your bank account class...
Member
Posts: 18,191
Joined: May 31 2010
Gold: 149.27
Sep 21 2014 04:43pm
Code
//------------------------------------------------------------------
// INTERFACE FILE: baccount.h
//
// Defines class bankAccount
// Declares the relational operators so bankAccount objects
// can be stored in standard containers such as list
//
//-------------------------------------------------------------------
// SAFEGUARDS AND INCLUDES
#ifndef BACCOUNT_H // Avoid redeclaring class bankAccount.
#define BACCOUNT_H // This code is compiled only once
#include <string> // for class string
using namespace std; // avoid having to write std:: as in std::string

///////////////////////////////////////////
/////// class bankAccount defintion ///////
///////////////////////////////////////////

class bankAccount {
public: // class member functions

//--constructors
bankAccount();

bankAccount(string initName, double initBalance);
// post: A bankAccount with two arguments when called like this:
// bankAccount anAcct("Hall", 100.00);

//--modifiers

void deposit(double depositAmount);
// post: depositAmount is credited to this object's balance

void withdraw(double withdrawalAmount);
// post: withdrawalAmount is debited from this object's balance

//--accessors

double balance() const;
// post: return this account's current balance

string name() const;
// post return the account name

private:
string my_name; // Uniquely identify an object
double my_balance; // Store the current balance (non-persistent)
};

//--Auxilliary functions

// With these two functions, bankAccount objects can be
// sorted and searched by the standard algorithms
bool operator < (const bankAccount & left, const bankAccount & right);
bool operator == (const bankAccount & left, const bankAccount & right);
bool operator != (const bankAccount & left, const bankAccount & right);
bool operator <= (const bankAccount & left, const bankAccount & right);
bool operator > (const bankAccount & left, const bankAccount & right);
bool operator >= (const bankAccount & left, const bankAccount & right);

#endif // ifndef BACCOUNT_H
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 21 2014 04:47pm
Well, I was right about name being a function that needed parens to be called.
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Sep 21 2014 05:03pm
Quote (KrzaQ2 @ Sep 21 2014 06:47pm)
Well, I was right about name being a function that needed parens to be called.


Yep. Still missing code though. It seems that this class template was created by his instructor I would imagine. I wonder if he created the actual class functions.
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Sep 21 2014 05:16pm
Quote (AbDuCt @ 22 Sep 2014 01:03)
Yep. Still missing code though. It seems that this class template was created by his instructor I would imagine. I wonder if he created the actual class functions.
Heh, that's actually far more reasonable assumption than mine. Although he's missing _WinMain@16, which suggests incorrect solution settings.
Member
Posts: 18,191
Joined: May 31 2010
Gold: 149.27
Sep 21 2014 05:33pm
I dont know whats going on :[
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll