deque container using stack class

I cannot, for the life of me, figure out why this thing wont compile. I'm getting an unresolved external. No errors or warnings. I'm lost

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//Author: Chris ******
//Date: 4/18/2011
//Purpose: Driver file for deque container: stack class
#include <iostream>
#include <deque>
#include <stack>

using namespace std;

//Purpose:function to add first 6 integers alternately to front and back of a deque
void AddAlt(deque<int> & D)
{
	for (int i = 1; i < 6; i++)
	{
		D.push_front(i++);
		D.push_back(i);
	}
}

//Purpose:a template function to display the content of a deque using iterator
template <typename T>
int Display(ostream & out, deque<T> & D)
{
	for (deque<int>::iterator it = D.begin(); it != D.end(); it++)
	{
		cout << *it << "   ";
	    cout << endl;
	}
}

//Purpose:a template function to change back value to a specified value 
template <typename T>
int changeBack(deque<T> & D, T item)
{
	while (!D.empty())
	{
		cin >> item;
		D.pop_back();
		D.push_back(item);
		cout << D.back() << "  ";
	}
	cout << endl;
}

template <typename T>
int main()
{
	
	int item;
	stack<T> stInt;    

	cout << "Enter item:" << endl;
	cin >> item;
	AddAlt(item);

	for (int i = 0; i < 6; i++)
	{
		stInt.push(i);
		Display(i);
	}

	stInt.push(item);
	changeBack(D, item);
	return 0;
}

What is the error exactly? Copy/paste it please.
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Always show the errors that you get. If too many, then start by showing what you think are the most relevant ones. Don't make us guess! :-)

Now, my guess, hehe: The linker doesn't find the main() function. That's because the one I see in your code is templated. That one cannot count as the program's main entry point.

I also see problems with your types. Example in line 54 where you call AddAlt(). The function requires that you pass as first (and only) argument a dequeue object, but instead you give it an int(eger).
if i remove the template <typename T> from before the main() function, then i get a whole bunch more squiggle lines (visual c++)
Last edited on
I know. Like I said, you have problems in your code. Maybe too many to discuss in a single thread. If you remove the template, you need to replace T with a valid data type, like int. After that, you need to correct line 54, and then we shall see what else remains.

And once more, remember to post the errors that you get.
Topic archived. No new replies allowed.