Avatar of jiwonman
jiwonman asked on

making set code for c++

Error      1      error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup      MSVCRTD.lib      

Error      2      fatal error LNK1120: 1 unresolved externals      C:\Documents and Settings\kjchung\My Documents\Visual Studio 2005\Projects\Project\Debug\Project.exe      1      

I get this two errors.. I am working for making a set code.

compiler used : vs 2005
#include <iostream>
class Element
	Element *next;
	int data;
	Element(Element *n, int d) : next(n),data(d){}
	~Element() { delete next;}
class Set
	Set() : first(0) {};
	Set(const Set& m);
	~Set() {delete first;}
	Set operator+ (const Set& m) const; //union
	Set operator^ (const Set& m) const; //intersect
	bool empty() const;
	bool member(int d) const;
	Element *first;
	Set(Element *p) : first(p) {};
void add(Element *& p, int d)
	if(!p || d< p-> data)
		 p= new Element(p,d);
	else if(p->data !=d)
void remove(Element *& p, int d)
	if(p &&p->data==d)
		Element *q=p;
		q->next = 0;
		delete q;
	else if(p && p->data <d)
Element *intersect(Element *p1, Element *p2)
	if(!p1 || !p2)
		return 0;
	else if (p1-> data == p2 -> data)
		return new Element(intersect(p1->next,p2->next),p1->data);
	else if (p1->data < p2->data)
		return intersect(p1->next,p2);
		return intersect(p1,p2->next);
Element *uni(Element *p1, Element *p2)
	if(!p1 && !p2)
		return 0;
		if(!p2 || (p1 && p1 ->data < p2->data))
			return new Element(uni(p1->next,p2),p1->data);
		else if(!p1 || (p2 && p2-> data < p1-> data))
			return new Element(uni(p1,p2->next), p2->data);
			return new Element(uni(p1->next,p2->next), p1->data);
Set Set::operator+ (const Set&m) const
	return Set(uni(first,m.first));
Set Set::operator^ (const Set& m) const
	return Set(intersect(first,m.first));

Open in new window


Avatar of undefined
Last Comment

8/22/2022 - Mon

Well, the error pretty much says it all - you need a 'main()' function which is the entry point for your program. Just add
int main ()
  // functionality goes here
  return 0;

Open in new window

Kent Olsen

Hi jiwonman,

While you're at it, add and remove should be part of class Set.

intersect and uni should probably be part of set Set, too.  But I can see why you might want to code them as you have already done.

Good Luck,

To add to jkr's comment:

the part

>>>> // functionality goes here

most likely is some test code for the Set class:

  Set anyset;

The last 2 statements are a guess as you didn't post the code for Set::member. I also would like to support Kent's suggestion to make the add, remove, intersect members of the Element class (or private members of class Set) rather than global functions, e. g.

Element*  Element::add(int d)
     Element * nextnext = NULL;
     if (next != NULL)
          nextnext = next->next;
          delete next;
     next = new Element(nextnext,d);
     return next;

The above code would insert a new node.

Regards, Alex

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

Thank you Kent. and Thank you for helping me numerous times Alex. problem solved.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question