undeclared identifier for vector

dont know how to construct the vecotr program.

Page 1 of 1

3 Replies - 2959 Views - Last Post: 24 February 2010 - 11:46 AM Rate Topic: -----

#1 zackburf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-February 10

undeclared identifier for vector

Posted 24 February 2010 - 11:16 AM

My program performs a banking action such as depositing or withdrawing money. They problem im now having is that im supposed to record all the actions in a vectors. Im having trouble finding examples, becuase I have to use separate classes. Help would be great. TY
THIS IS THE HEADER FILE

#ifndef TRANSACTION
#define TRANSACTION

#include<iostream>
#include<string>
#include<vector>
using namespace std;


class Transaction {
	private:
		vector <string> transactionRecord;
	public:
		void addNewTransaction(string);
		void displayTransactions();
};

#endif
THIS IS THE CPP FILE
#include<iostream>
#include "transaction.h"
#include <vector>
using namespace std;

void Transaction::addNewTransaction(string);
	Transaction.push_back(string);

void Transaction::displayTransactions();
	for (int i=0; i<Transaction.size(); i++) {
		cout<<Transaction.at(0)<<"\n";



Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: undeclared identifier for vector

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: undeclared identifier for vector

Posted 24 February 2010 - 11:30 AM

Transaction.push_back(string);


Transaction is the class itself, and it does not have a .push_back method. .push_back is specific to std::vector. The only vector in your class is "transactionRecord". Did you mean to use it here, instead of Transaction?
EDIT:
void Transaction::addNewTransaction(string)


Here, you must give a name to the function parameter. Seriously, does this seem logical to you:
push_back(string);


You are trying to insert the whole "std::string" class, to your vector ...

This post has been edited by sarmanu: 24 February 2010 - 11:31 AM

Was This Post Helpful? 0
  • +
  • -

#3 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1086
  • View blog
  • Posts: 4,563
  • Joined: 09-June 09

Re: undeclared identifier for vector

Posted 24 February 2010 - 11:43 AM

Your not declaring your function write in your cpp, and also if you include a header in your header file, you dont have to reinclude it in the cpp file.

example of your cpp file function
void Transaction::addNewTransaction(string line)//<--- a variable name 
{//<---brackets
        transactionRecord.push_back(string); 
}//<---brackets
 
void Transaction::displayTransactions()
{
        for (int i=0; i<transactionRecord.size(); i++)
                cout<<transactionRecord[i]<<endl;
}


This post has been edited by ImaSexy: 24 February 2010 - 11:45 AM

Was This Post Helpful? 1
  • +
  • -

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: undeclared identifier for vector

Posted 24 February 2010 - 11:46 AM

Lol I didn't even see that he did not use brackets. Thanks IMASEXY!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1