8 Replies - 1741 Views - Last Post: 26 July 2011 - 05:49 PM Rate Topic: -----

#1 machoolah  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 87
  • Joined: 17-May 09

ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:14 PM

Hello everyone,

I am trying to create a class with a list of a user-defined data type as its member. I get the error: ISO C++ forbids declaration of 'list' with no type. Could anyone tell me what I should change in the code to get it to work? (in util.h line 13)

Thanks!

Filename: main.cpp
#include<iostream>
#include<list>

#include "util.h"

using namespace std;

REFERENCE_SET ref_set;

int main(){

	REFERENCE_SET s;
	return 0;
}


Filename: util.h
#ifndef UTIL_H
#define UTIL_H

class ARRAY{
public:
	int ele[100];
	int size;		
	ARRAY();
};

class REFERENCE_SET{
public:
	list<ARRAY> perm;
	int size; 
	
	REFERENCE_SET();
};

#endif


Filename: util.cpp
#include "util.h"

ARRAY::ARRAY(){
	size = 0;
}


REFERENCE_SET::REFERENCE_SET(){
	size = 0;
}

This post has been edited by machoolah: 26 July 2011 - 05:17 PM


Is This A Good Question/Topic? 0
  • +

Replies To: ERROR: ISO C++ forbids declaration of 'list' with no type

#2 GWatt  Icon User is offline

  • member icon

Reputation: 262
  • View blog
  • Posts: 3,054
  • Joined: 01-December 05

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:23 PM

It does not appear that you have included the list header in util.h. Since your class declaration is in util.h is uses list there.
Was This Post Helpful? 0
  • +
  • -

#3 machoolah  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 87
  • Joined: 17-May 09

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:28 PM

That doesn't solve the problem! I still get the same error. Can you tell me where exactly I should include the header?
Was This Post Helpful? 0
  • +
  • -

#4 GWatt  Icon User is offline

  • member icon

Reputation: 262
  • View blog
  • Posts: 3,054
  • Joined: 01-December 05

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:35 PM

/*
 util,h
*/
#ifndef UTIL_H
#define UTIL_H

#include <list> // INCLUDE LIST HERE

class ARRAY{
public:
	int ele[100];
	int size;		
	ARRAY();
};

class REFERENCE_SET{
public:
	list<ARRAY> perm;
	int size; 
	
	REFERENCE_SET();
};

#endif


Was This Post Helpful? 0
  • +
  • -

#5 machoolah  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 87
  • Joined: 17-May 09

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:39 PM

I still get the same error! =(
Was This Post Helpful? 0
  • +
  • -

#6 GWatt  Icon User is offline

  • member icon

Reputation: 262
  • View blog
  • Posts: 3,054
  • Joined: 01-December 05

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:40 PM

You also need to specify the namespace containing list, sinc it's not in the global namespace.
std::list<TYPE> obj;


Was This Post Helpful? 2
  • +
  • -

#7 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,396
  • Joined: 19-February 09

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:41 PM

You probably want the std namespace as well.

std::list<ARRAY> perm;


Was This Post Helpful? 1
  • +
  • -

#8 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,735
  • Joined: 25-December 09

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:43 PM

The list class is in the namespace std, so you need to use the scope resolution operator for the std namespace, std::list<ARRAY> perm;

Jim
Was This Post Helpful? 1
  • +
  • -

#9 machoolah  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 87
  • Joined: 17-May 09

Re: ERROR: ISO C++ forbids declaration of 'list' with no type

Posted 26 July 2011 - 05:49 PM

WOW, thanks for all your replies. This works perfectly now! =)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1