Code compiles in Dev C++ but not Visual

This school project accepts integers into a custom data type called "set". Set is a list that accepts and manipulates integers. This is my first time using templates. The code will compile perfectly in Dev C++ but not visual studio 2010 express. My error codes are at the bottom. (I also have an application file that has been omitted since all of the errors are in the .template file.)
Thanks for your help.


header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef SETTEM_H
#define SETTEM_H
#include <list>

namespace Swirly_Stem
{
	template<class T>
	class set
	{
	public:	
		typedef int value_type;
		typedef std::size_t size_type;
		static const size_type CAPACITY=30;

		//constructor
		set() {used = 0;}

		//MODIFICATION MEMBER FUNCTIONS 
	public:
			bool erase_one(const T& target);	
			void insertation2(const T& entry);
			//set operator+ (const set& addend);
			//void operator+=(const set& addend);
			bool contains2(const T& entry);
			std::list <value_type> data;
	//CONSTANT MEMBER FUNCTION

			size_type size() const {return used;};
			
	private:
		size_type used;
	
	};
//NONMEMBER FUNCTION

}
#include "setTemplates.template"
#endif 


.template file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cmath>
#include <cassert>
#include <list>
#include <iterator>
#include <algorithm>
using namespace std; 
namespace Swirly_Stem
 {
	std::list<int>::iterator iter;

	 template <class T>
	bool set<T>::erase_one(const T& target)
	{

		value_type index;
		index = 0;
		for(iter=data.begin();iter!=data.end();++iter)
		{		
		if (iter == data.end())
			{
				return false;		
			}
		}
		data.erase(iter);
		//i would use pop back but this handles the erase from the center too.
		return true;
	};
	
	 template<class T>
	void set<T>::insertation2(const T& entry)
	{
		data.push_back(entry);//first in is last data element.
		data.unique();//This enforces all data to be unique
	}
	
	
	 template<class T>
 	bool set<T>::contains2(const T& entry)
	{
		size_type i=0;
		bool returner = true;		
		return returner;
	}
}


Error messages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
c:snip\settemplates\settemplates.template(13): error C2143: syntax error : missing ';' before '<'

c:snip\settemplates\settemplates.template(13): error C2988: unrecognizable template declaration/definition

c:snip\settemplates\settemplates.template(13): error C2059: syntax error : '<'

c:snip\settemplates\settemplates.template(13): error C2039: 'erase_one' : is not a member of '`global namespace''

c:snip\settemplates\settemplates.template(31): error C2143: syntax error : missing ';' before '<'

c:snip\settemplates\settemplates.template(31): error C2182: 'set' : illegal use of type 'void'

c:snip\settemplates\settemplates.template(31): error C2371: 'Swirly_Stem::set' : redefinition; different basic types

c:snip\settemplates\settemplates.template(21) : see declaration of 'Swirly_Stem::set'

c:snip\settemplates\settemplates.template(39): error C2988: unrecognizable template declaration/definition

c:snip\settemplates\settemplates.template(31): error C2059: syntax error : '<'

c:snip\settemplates\settemplates.template(39): error C2039: 'insertation2' : is not a member of '`global namespace''

c:snip\settemplates\settemplates.template(39): error C2039: 'contains2' : is not a member of '`global namespace''

c:snip\settemplates\settemplates.template(40): error C2143: syntax error : missing ';' before '{'

c:snip\settemplates\settemplates.template(40): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 
Looks like Visual Studio is trying to compile the setTemplates.template file.

Because you are including this file as part of the header file - you need to tell visual studio not to try compiling it as a separate file.

In the solutions window - right click on the file and bring up the properties dialog box.

In the General section - make sure the Item Type property is set to Does not participate in build.

hopefully that will cure the problem.
You have a few semicolons in the middle of nowhere, your list should be public. Your erase_one never erases anything and doesn't do anything with the value it has been passed to. None of your methods work with anything except set<int>, and quite frankly I have absolutely no idea why your set is a template, as you never do anything with the type parameter.
Last edited on
That fixed the problem. Thank you so much, it never would have occurred to me to do that!
No probs.
Topic archived. No new replies allowed.