2 Replies - 582 Views - Last Post: 07 October 2012 - 12:23 PM Rate Topic: -----

#1 Granolaisgood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-September 12

Compiler saying cout is undeclared despite having #include <iostre

Posted 07 October 2012 - 11:57 AM

Like the title says, I keep on getting an error compiler message saying cout is undeclared. Here is what extactly the compiler says: " `virtual T ABList<T>::remove(int)':
ABList.hpp:93: error: expected `{' before "cout"
ABList.hpp:93: error: `cout' undeclared (first use this function)"

here is the code that is having problem.
virtual T    remove (int pos);//Function protype

template <class T>
T ABList<T>::remove (int pos)
{
	try
	{
		if(pos < 1)
			throw 3;
		else
		{
			T temp =  a[pos -1];
		
			for(int i = pos-1; i < size; i++)
			{
				a[i] = a [i+1];
				--size;
			}
			return temp;
		}
	}
	catch(int x)
		cout << "ERROR: " << x;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Compiler saying cout is undeclared despite having #include <iostre

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Compiler saying cout is undeclared despite having #include <iostre

Posted 07 October 2012 - 12:03 PM

Show us the entire file. Also your catch should have brackets.

Even if you have the iostream header, you need to include the namespace as well or cout by itself or fully qualify it in your code.
Was This Post Helpful? 1
  • +
  • -

#3 Granolaisgood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 30-September 12

Re: Compiler saying cout is undeclared despite having #include <iostre

Posted 07 October 2012 - 12:23 PM

View PostKYA, on 07 October 2012 - 12:03 PM, said:

Show us the entire file. Also your catch should have brackets.

Even if you have the iostream header, you need to include the namespace as well or cout by itself or fully qualify it in your code.


here it is
/*
Muhammad Zubair
Assignment 2
CSCI 235 Section 001
*/

#ifndef _CS235_ABLIST_H_
#define _CS235_ABLIST_H_


#define LIST_MAX 10

#include "ABCList.hpp"
#include<iostream>
using namespace std;
template <class T>
class ABList : public ABCList<T> {
private:
	T    a [LIST_MAX];
	int  size;

public:
	     ABList ();

	virtual bool isEmpty ();
	virtual int  getLength ();
	virtual void insert (int pos, T item);
	virtual T    remove (int pos);
	virtual T    retrieve (int pos);
};


template <class T>
ABList<T>::ABList () {
	size = 0;
}

template <class T>
bool ABList<T>::isEmpty () {
	if (size == 0)
		return true;
	return false;
}

template <class T>
int  ABList<T>::getLength ()
{
	return size;
}

template <class T>
void ABList<T>::insert (int pos, T item)
{
	try
	{
		if(pos < 1)
			throw 2;
		else
		{
		for(int i= size; i> i-1; i--)
		{
			item [i] = item [i-1];
			item [pos-1] = item; 
			++size;
		}
		}
	}
		catch(int x)
			{cout << "Error Number" << x;}
	
}

template <class T>
T ABList<T>::remove (int pos)
{
	try
	{
		if(pos < 1)
			throw 3;
		else
		{
			T temp =  a[pos -1];
		
			for(int i = pos-1; i < size; i++)
			{
				a[i] = a [i+1];
				--size;
			}
			return temp;
		}
	}
	catch(int x)
		{cout << "ERROR: " << x;}
}

template <class T>
T ABList<T>:: retrieve (int pos)
{
	if(pos >= 1)
		return a[pos - 1];
	else
		return NULL;
}


#endif



View PostKYA, on 07 October 2012 - 12:03 PM, said:

Show us the entire file. Also your catch should have brackets.

Even if you have the iostream header, you need to include the namespace as well or cout by itself or fully qualify it in your code.


Nevermind i got it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1