Why wont this simple class compile?

This is a discussion on Why wont this simple class compile? within the C++ Programming forums, part of the General Programming Boards category; Why will this not compile. More specifically what am I doing wrong? Code: /********************************************* ** Module: car.h ********************************************/ #ifndef _CAR_H_ ...

  1. #1
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Posts
    50

    Question Why wont this simple class compile?

    Why will this not compile. More specifically what am I doing wrong?

    Code:
    /*********************************************
     **  Module: car.h
     ********************************************/
    #ifndef _CAR_H_
    #define _CAR_H_
    
    #include <cstdlib>
    #include <iostream.h>
    
    class CCar {
        int color;
    
     public:
        CCar();
        ~CCar();
        void drive();
    };
    #endif
    Code:
    /*********************************************
     **  Module: car.cc
     ********************************************/
    #include "car.h"
    
    CCar::CCar(){
        color = 1;
        cout << "Creating CCar." << endl;
    }
    
    CCar::~CCar(){
        cout << "Destroying CCar." << endl;
    }
    
    void CCar::drive(){
        cout << "Driving CCar." << endl;
    }
    Code:
    /*********************************************
     **  Module: driver.cc
     ********************************************/
    #include <iostream.h>
    #include <cstdlib>
    #include "car.h"
    
    int main(){
      // Create some vehicles.
      CCar        *pCar        = new CCar;
    
      // Use the vehicles.
      pCar->drive();
    
      // Cleanup.
      if ( pCar ){ delete pCar; }
    
      exit ( 0 );
    }
    Compile Error:
    hpux-02# aCC -o crap driver.cc
    /usr/ccs/bin/ld: Unsatisfied symbols:
    CCar::DrawCar() (first referenced in driver.o) (code)
    CCar::CCar() (first referenced in driver.o) (code)
    CCar::~CCar() (first referenced in driver.o) (code)

    As always thanks in advance for any help.

    DeadPoet

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    You need to compile, and link with, car.cc

    I don't know your compiler tools, but here is a guess:

    >> hpux-02# aCC -o crap driver.cc car.cc

    gg

  3. #3
    Registered User deadpoet's Avatar
    Join Date
    Jan 2004
    Posts
    50

    Smile

    Dude, you are quick! I am using HP's softbench. Thanks a Million.



    DeadPoet

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 05:30 AM
  2. Simple Class definition
    By Emeighty in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 03:55 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. simple class
    By Perverse in forum C++ Programming
    Replies: 4
    Last Post: 01-28-2005, 05:55 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21