this is the main program
# include "list_3358.h"
# include "stack_3358.h"
# include <iostream>
# include <string>
# include <fstream>
#include <vector>

using namespace std;
using namespace stack;
using namespace linked_list;

int main(int argc,char* argv[])
{
string str;
str=argv[1];
STACK_3358<string> stack1;


//ifstream infile( str );
ifstream file_op( str.c_str() );

do
{
string line,equ;
getline(file_op,line);
vector<string> readline;
readline.push_back(line);

for( int i = 0; i < readline.size() ; i++ )
{
equ=readline;
if( "(" == equ)
{
stack1.push(equ);
}
else if( "{" == equ)
{
stack1.push(equ);
}
else if ( "<" == equ)
{
stack1.push(equ);
}
else if ( "[" == equ)
{
stack1.push(equ);
}
else if(stack1.gettop()==equ)
{
if(!stack1.isempty())
{
stack1.pop();
}
if(stack1.gettop()!=equ)
cout << "Missing"<<equ<<endl;

}
else
return 0;

}


if(stack1.isempty())
cout<<" valid expression"<<endl;


}while(!file_op.eof());

file_op.close();
return 0;
}


and I am getting errors like this
equation_test.cpp: In function `int main(int, char**)':
equation_test.cpp:34: error: no matching function for call to `stack::STACK_3358<std::string>::push(int)'
stack_3358.h:31: note: candidates are: void stack::STACK_3358<Item>::push(Item&) [with Item = std::string]
stack_3358.h: In member function `void stack::STACK_3358<Item>::push(Item&) [with Item = std::string]':
equation_test.cpp:38: instantiated from here
stack_3358.h:32: error: cannot call member function `void linked_list::LIST_3358<Item>::insertAtHead(Item&) [with Item = std::string]' without object
stack_3358.h: In member function `Item stack::STACK_3358<Item>::gettop() [with Item = std::string]':
equation_test.cpp:48: instantiated from here
stack_3358.h:58: error: cannot call member function `Item& linked_list::LIST_3358<Item>::getdata() [with Item = std::string]' without object
stack_3358.h: In member function `bool stack::STACK_3358<Item>::isempty() [with Item = std::string]':
equation_test.cpp:50: instantiated from here
stack_3358.h:47: error: cannot call member function `size_t linked_list::LIST_3358<Item>::getcurrentsize() [with Item = std::string]' without object
stack_3358.h: In member function `void stack::STACK_3358<Item>::pop() [with Item = std::string]':
equation_test.cpp:52: instantiated from here
stack_3358.h:40: error: cannot call member function `void linked_list::LIST_3358<Item>::deleteAtHead() [with Item = std::string]' without object

please help me to solve this.

Recommended Answers

All 4 Replies

1) Code Tags
2) Provide all the code that is the problem - this is may include header files etc

Chris

Stack may not have a function push to push string , check definition of stack.

This is my code:
list header file

#ifndef LIST_3358_H
#define LIST_3358_H

# include <iostream>
#include<string>
#include<cstdlib>
using namespace std;
namespace linked_list
{
template <class Item>
class LIST_3358
{
public:
typedef Item value_type;
typedef size_t size_type;
LIST_3358();
//LIST_3358(LIST_3358 & src);
~LIST_3358();
void insertAtHead(Item & entry);
void deleteAtHead();
size_type getcurrentsize()
{
return currentsize;
}
Item & getdata()
{
return head->data;
}
size_type currentsize;
private:
struct node
{
Item data;
node* next;
};
node* head;
node* tail;
node* cursor;
};
template <class Item>
LIST_3358<Item>::LIST_3358()
{
head=cursor=tail=NULL;
currentsize=0;
}
template <class Item>
LIST_3358<Item>::~LIST_3358()
{
node* nodeptr;
node* nextnodeptr;
nodeptr=head;
while(nodeptr!=NULL)
{
delete nodeptr;
nodeptr=nextnodeptr;
}
}
template <class Item>
void LIST_3358<Item>::insertAtHead(Item & entry)
{
node* newnode;
newnode=new node();
newnode->next=head;
head=newnode;
head->data=entry;
currentsize++;
}
template <class Item>
void LIST_3358<Item>::deleteAtHead( )
{
node* nodeptr;
nodeptr=head;
head=head->next;
delete nodeptr;
currentsize--;
}

}
#endif

this is the stack header file
#include "list_3358.h"

#ifndef STACK_3358_H
#define STACK_3358_H
#include<iostream>
#include<cstdlib>

using namespace std;
namespace stack
{
template <class Item>

class STACK_3358
{
public:
typedef size_t size_type;
typedef Item value_type;
STACK_3358()
{
value_type top=NULL;
}
void push(Item & entry);
void pop();
bool isempty();
Item gettop();

};

template <class Item>
void STACK_3358<Item>::push(Item & entry)
{
linked_list::LIST_3358<Item>::insertAtHead(entry);


}

template <class Item>
void STACK_3358<Item>::pop()
{
linked_list::LIST_3358<Item>::deleteAtHead();
}


template <class Item>
bool STACK_3358<Item>::isempty()
{
size_type currentsize = linked_list::LIST_3358<Item>::getcurrentsize();
if(currentsize!=0)
return true;
else
return false;
}


template <class Item>
Item STACK_3358<Item>::gettop()
{
value_type top = linked_list::LIST_3358<Item>::getdata();
return top;
}
}

#endif

I have created a object.but the error is cannot access without object/what does the the error instantiated here mean?

please help me

commented: OK, you missed all the code tags on entry to the forum, you missed code tags in a reply, are you that stupid? -4

So besides ignoring the fact i told you to use code tags, you have posted ALL of your code anyway.

Also narrow it down a little bit, rather than just postig the whole lot with an error message

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.