Trouble with containers

Hi there. I recently had to create my own container class for a project, however I am having some trouble in getting it to work and would be grateful for any help.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <algorithm>
#include <assert.h>
#include "bag.h"

const bag::size_type bag::Capacity;

bag::size_type bag::erase(const value_type& target)
{
	size_type index = 0;
	size_type many_removed = 0;
	while (index < used)
	{
		if (data[index] == target)
		{
			used--;
			data[index] = data[used];
			many_removed++;
		}
		else
		{
			index++;
		}
	}
	return many_removed;
}

bool bag::erase_one(const value_type& target)
{
	size_type index;
	index = 0;
	while ((index < used) && (data[index] != target))
	{
		index++;
	}
	if (index == used)
	{
		return false;
	}

	used--;
	data[index] = data[used];
	return true;
}

void bag::insert(const value_type& entry)
{
	assert(size() < Capacity);
	used++;
}

void bag::operator +=(const bag& addend)
{
	assert(size() + addend.size() <= Capacity);
	used += addend.used;
}

bag::size_type bag::count(const value_type& target) const
{
	size_type answer;
	size_type i;

	answer = 0;
	for (i = 0; i < used; i++)
	{
		if (target == data[i])
		{
			answer++;
		}
	}
	return answer;
}

bag operator +(const bag& b1, const bag& b2)
{
	bag answer;

	assert(b1.size() + b2.size() <= bag::Capacity);

	answer += b1;
	answer += b2;
	return answer;
}



This is my code, the problem I am having is that recently when trying to compile I have been getting the following error:

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

I am quite new to C++, though I didn't think this was a beginner problem so I put it here. Any help would be greatly appreciated, but how do I get rid of this error?

Thanks in advance
closed account (zb0S216C)
Where's main( )?

Wazzak
Every console program needs to have the function: int main() defined somewhere. That is where we start the program. Without that function, our program won't go anywhere. You need to add that function if you want to run this as an executable.

It's also possible that you are writing a library or DLL. In that case you won't need int main(). The executable that calls your DLL will have the int main().
/facepalm
Thanks guys, that was a bit stupid on my part. I got so caught up in trying to make the cpp work that I forgot to make a main!

Guess this was a beginner problem after all

Thanks again :)
Last edited on
Topic archived. No new replies allowed.