When I compiled this program...

#include<iostream>
using namespace std;
class base
{
    public:
      virtual void show()
      {
                cout<<"\n  Base class show:";
      }
      void display()
      {
              cout<<"\n  Base class display:" ;
      }
};
 
class drive:public base
{
   public:
      void display()
      {
              cout<<"\n  Drive class display:";
      }
      void show()
      {
              cout<<"\n  Drive class show:";
      }
};
 
int main()
{
   
   base obj1;
   base *p;
   cout<<"\n\t P points to base:\n"  ;
 
   p=&obj1;
   p->display();
   p->show();
 
   cout<<"\n\n\t P points to drive:\n";
   drive obj2;
   p=&obj2;
   p->display();
   p->show();
   return 0;
}

I got these messages.. Can anyone tell me what Im doing wrong?

/tmp/cckMKZwu.o: In function `main':
virtual.cpp:(.text+0x1a): undefined reference to `std::cout'
virtual.cpp:(.text+0x1f): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
virtual.cpp:(.text+0x50): undefined reference to `std::cout'
virtual.cpp:(.text+0x55): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cckMKZwu.o: In function `__static_initialization_and_destruction_0(int, int)':
virtual.cpp:(.text+0xb6): undefined reference to `std::ios_base::Init::Init()'
virtual.cpp:(.text+0xbb): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cckMKZwu.o: In function `base::show()':
virtual.cpp:(.text._ZN4base4showEv[base::show()]+0x12): undefined reference to `std::cout'
virtual.cpp:(.text._ZN4base4showEv[base::show()]+0x17): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cckMKZwu.o: In function `base::display()':
virtual.cpp:(.text._ZN4base7displayEv[base::display()]+0x12): undefined reference to `std::cout'
virtual.cpp:(.text._ZN4base7displayEv[base::display()]+0x17): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cckMKZwu.o: In function `drive::show()':
virtual.cpp:(.text._ZN5drive4showEv[drive::show()]+0x12): undefined reference to `std::cout'
virtual.cpp:(.text._ZN5drive4showEv[drive::show()]+0x17): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cckMKZwu.o:(.rodata._ZTI5drive[typeinfo for drive]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/tmp/cckMKZwu.o:(.rodata._ZTI4base[typeinfo for base]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'

'

Please help. gcc -v gives:

gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

OMg omg! I found the solution... I should use g++ instead of gcc.. hehe Thanks anyway :)

OMg omg! I found the solution... I should use g++ instead of gcc.. hehe Thanks anyway :)

Yeah that would do it. Did it myself from time to time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.