Thread: Help with inheritance using modules

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    8

    Question Help with inheritance using modules

    I have two classes, Entry and PersonalEntry, which is derived from Entry.

    The class Entry is in two files, Entry.h and Entry.cpp and PersonalEntry is in PersonalEntry.h and PersonalEntry.cpp

    I am trying to create a derived class constructor in PersonalEntry from Entry but I keep getting the following error message:

    error C2969: syntax error : ';' : expected member function definition to end with '}'

    Any ideas as to why this is happening?

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Post a few lines of code around the error. You are probably missing a semicolon or brace.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    8
    Thanks for your reply. Here are the contents of four of the files I'm using.

    Entry.h
    Code:
    #ifndef __ENTRY_H
    #define __ENTRY_H
    
    #include <string.h>
    
    using namespace std;
    
    class CAddressBookEntry 
    {
     public:
      CAddressBookEntry();
      CAddressBookEntry(char* pLastName, char* pFirstNames, char* pStreet, char* pSuburb, char* pCity, char* 
    pMobilePhoneNumber);
      ~CAddressBookEntry();
      
     private:
      char LastName[20];
      char FirstNames[20];
      char Street[20];
      char Suburb[15];
      char City[15];
      char MobilePhoneNumber[15];
    };
    
    #endif
    Entry.cpp
    Code:
    #include "Entry.h"
    #include <string>
    
    //using namespace std;
    
    CAddressBookEntry::CAddressBookEntry() 
    {
      strcpy(LastName, "null");
      strcpy(FirstNames, "null");
      strcpy(Street, "null");
      strcpy(Suburb, "null");
      strcpy(City, "null");
      strcpy(MobilePhoneNumber, "null");
    };
    
    CAddressBookEntry::CAddressBookEntry(char* pLastName, char* pFirstNames, 
    char* pStreet, char* 
    pSuburb, char* pCity, char* pMobilePhoneNumber)
    {
      strcpy(LastName, pLastName);
      strcpy(FirstNames, pFirstNames);
      strcpy(Street, pStreet);
      strcpy(Suburb, pSuburb);
      strcpy(City, pCity);
      strcpy(MobilePhoneNumber, pMobilePhoneNumber);
    };
    
    CAddressBookEntry::~CAddressBookEntry()
    {
      //nothing doing
    };
    PersonalEntry.h
    Code:
    #ifndef __PERSONALENTRY_H
    #define __PERSONALENTRY_H
    
    #include <string.h>
    #include "Entry.h"
    #include "Entry.cpp"
    
    using namespace std;
    
    class CPersonalEntry: public CAddressBookEntry
    {
     public:
      CPersonalEntry():CAddressBookEntry();
      CPersonalEntry(char* pLastName, char* pFirstName, char* pStreet, char* pSuburb, char* pCity, char*  
    pMobilePhoneNumber, char* HomePoneNumber, char* HomeEmailAddress):CAddressBookEntry(pLastName, pFirstName, pStreet, 
    pSuburb, pCity, pMobilePhoneNumber);
     private:
      char HomePhoneNumber[15];
      char HomeEmailAddress[15];
    };
    
    #endif
    PersonalEntry.cpp
    Code:
    #include "PersonalEntry.h"
    #include "Entry.h"
    #include <string>
    
    //using namespace std;
    
    CPersonalEntry::CPersonalEntry()
    {
      strcpy(HomePhoneNumber, "null");
      strcpy(HomeEmailAddress, "null");
    }
    
    CPersonalEntry::CPersonalEntry(char* pLastName, char* pFirstName, char* 
    pStreet, char* pSuburb, char* pCity, char*  
    pMobilePhoneNumber, char* HomePoneNumber, char* 
    HomeEmailAddress):CAddressBookEntry(pLastName, pFirstName, pStreet, 
    pSuburb, pCity, pMobilePhoneNumber)
    {
      strcpy(HomePhoneNumber, pHomePhoneNumber);
      strcpy(HomeEmailAddress, pHomeEmailAddress);
    }
    
    CPersonalEntry::~CPersonalEntry() {};

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    8
    Found my problem, it was in the header files.

    For example, where I put
    Code:
    class CPersonalEntry: public CAddressBookEntry
    {
     public:
      CPersonalEntry():CAddressBookEntry();
    I should have only put

    Code:
    class CPersonalEntry: public CAddressBookEntry
    {
     public:
      CPersonalEntry();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  4. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM