Jump to content


Photo

C++


  • Please log in to reply
9 replies to this topic

#1 Slip

Slip

    X-S Senior Member

  • Members
  • PipPip
  • 190 posts

Posted 19 February 2003 - 03:59 PM

Ok so I was doing a bit of begginer programming today (working on Classes and Inheritance) and made this program, from what I see it should work but I get theses two errors whenever I try to build:
--------------------Configuration: TestClass - Win32 Debug--------------------
Compiling...
Code.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/TestClass.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

TestClass.exe - 2 error(s), 0 warning(s)


#include <iostream>

class CAnimal
{
public:
int m_MaxAge;
int m_Age;

CAnimal ();
virtual ~CAnimal();

virtual void Talk(void);

};


CAnimal::CAnimal ()
{
m_MaxAge = 0;
m_Age = 0;
}

CAnimal::~CAnimal ()
{
}

void CAnimal::Talk (void)
{
std::cout<<"Base animals do no talking!";
}

class CDog : public CAnimal
{
public:
CDog ();
virtual ~CDog ();

virtual void Talk (void);
};

CDog::CDog ()
{
m_MaxAge=9;
m_Age=0;
}

CDog::~CDog ()
{
}

void CDog::Talk (void)
{
if(m_Age < m_MaxAge)
{
std::cout<<"Bark!"<<std::endl;
m_Age ++;
}
}

class CCat : public CAnimal
{
public:
CCat();
virtual ~CCat();

virtual void Talk (void);

};

CCat::CCat ()
{
m_MaxAge = 5;
m_Age = 0;
}

CCat::~CCat()
{
}

void CCat::Talk (void)
{
if (m_Age < m_MaxAge)
{
std::cout<<"Meow!"<<std::endl;
m_Age ++;
}
}

int Main()
{
CDog Dog;
CCat Cat;
int Loop;

for (Loop = 0; Loop < 10; Loop ++)
{
Dog.Talk ();
Cat.Talk ();
}

return 0;

}

Can anyone help me out, cant figure out what thoes errors are dry.gif
sorry for the long post

Edited by Slip, 19 February 2003 - 03:59 PM.


#2 yanke10

yanke10

    X-S Expert

  • XS-BANNED
  • PipPipPip
  • 551 posts
  • Xbox Version:unk

Posted 19 February 2003 - 04:11 PM

shouldnt it be iostream.h

i forgot, havent coded in a lond time

#3 phantazma1

phantazma1

    X-S Freak

  • Members
  • PipPipPipPipPip
  • 1,312 posts

Posted 19 February 2003 - 04:23 PM

QUOTE (yanke10 @ Feb 19 2003, 10:11 AM)
shouldnt it be iostream.h

i forgot, havent coded in a lond time

yup, iostream.h should be the header file.

and why do you have 2 of these?

CCat::~CCat()
{
}

delete one of them.

if you are using unix as the os, then delete all the files except your cpp,h, and makefile.
recompile


#4 ASheva10

ASheva10

    X-S Freak

  • Members
  • PipPipPipPipPip
  • 1,449 posts

Posted 19 February 2003 - 04:41 PM

yeah, I think that the header is the problem

#include <iostream.h>

#5 J.P. Patches

J.P. Patches

    X-S Expert

  • Members
  • PipPipPip
  • 571 posts

Posted 19 February 2003 - 06:09 PM

Well... Your problem, as the linker has told you, is that you have no main() function. What you do have, however, is a Main() function.

main != Main

Case sensitive.

#6 BenJeremy

BenJeremy

    X-S Elysian

  • Head Moderators
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 9,690 posts
  • Gender:Male
  • Xbox Version:v1.1
  • 360 version:v1 (xenon)

Posted 19 February 2003 - 06:46 PM

Since you are using the 'std' namespace, I have to assume #include <iostream> is valid.

This is something used with Standard Template Libraries (STL).

Template headers don't have the ".h" in them.

#7 Slip

Slip

    X-S Senior Member

  • Members
  • PipPip
  • 190 posts

Posted 19 February 2003 - 07:29 PM

Thanks BenJeremy, yeah im using the new standards, thats what my book told me to do

Edited by Slip, 19 February 2003 - 07:31 PM.


#8 Slip

Slip

    X-S Senior Member

  • Members
  • PipPip
  • 190 posts

Posted 19 February 2003 - 07:30 PM

Sweet it worked, stupid case sensitive thing laugh.gif

#9 J.P. Patches

J.P. Patches

    X-S Expert

  • Members
  • PipPipPip
  • 571 posts

Posted 19 February 2003 - 07:34 PM

Glad I could be of service.

#10 Schmo

Schmo

    X-S Freak

  • Members
  • PipPipPipPipPip
  • 1,150 posts
  • Xbox Version:v1.2
  • 360 version:v1 (xenon)

Posted 19 February 2003 - 07:36 PM

Replace:
int Main()

with:
int main(int argc, char* argv[])

That should do it.


Hmmm... everyone beat me to it.

Edited by Schmo, 19 February 2003 - 07:44 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users