FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Trouble with Inheritance





LanyardLad
Hey, I'm pretty new to programming and I've come across a problem that I can't figure out. I'm writing code to cipher and decipher messages but my message classes are having trouble with inheritance it seems. Here's the errors I get:

EncryptedMessage.h:9: error: expected class-name before '{' token
EncryptedMessage.h:13: error: expected ')' before 'fin'

This is the header for my EncryptedMessage sub class.
Code:
#include <iostream>
#include <fstream>

#include "Message.h"
#include "Cipher.h"
#include "CaesarCipher.h"
#include "RSACipher.h"

class EncryptedMessage: public Message {
        char text[];
        int size;
public:
        EncryptedMessage(ifstream fin)

        ~EncryptedMessage()

        void print(ofstream fout)

        int length()

        void cat(Message new_text)

        void CaesarCipher(CaesarCipher cipher, Message message, EncryptedMessage en_message, int key)

        void RSACipher(RSACipher cipher, Message message, EncryptedMessage en_message, char *key)

}




So this the source code for my EncryptedMessage sub class.
Code:

#include <iostream>
#include <fstream>

#include "Message.h"
#include "EncryptedMessage.h"
#include "Cipher.h"
#include "CaesarCipher.h"
#include "RSACipher.h"
//#include "BigIntegerLibrary.hh"

using namespace std;

EncryptedMessage::EncryptedMessage(ifstream fin)
{
        int i = 0, size = 101;
        text = new char(size);
        while(!text.eof())
        {
                fin >> text[i];
                i++;
                if(i = (size - 1))
                {
                        char *temp;
                        temp = new char(size);
                        temp = text;
                        delete text;
                        size += 100;
                        text = new char(size);
                        text = temp;
                        delete temp;
                }
        }

EncryptedMessage::~EncryptedMessage()
{
        delete text;
}
int Message::length()
{
        int i;
        while(text[i] != eof)
        {
                i++;
                return(size);
        }
}
void EncryptedMessage::print(ofstream fout)
{
        fout << "The encrypted message is: " << text << endl;
}
void Message::CaesarCipher(CaesarCipher cipher, Message message, EncryptedMessage en_message, int key)
{
        cipher.CaesarCipher(key);
        cipher.decrypt(key, message, en_message);
}
void Message::RSACipher(RSACipher cipher, Message message, EncryptedMessage en_message, char *key)
{
        cipher.RSACipher(key);
        cipher.decrypt(key, message, en_message);
}


Any help would be greatly appreciated. Also, on a side not I need help storing an int into a character array so that I have an array of ints that I can print out later.
Peterssidan
Quote:
EncryptedMessage.h:9: error: expected class-name before '{' token
This looks like it can't find the class named Message. Is it defined in Message.h?

Quote:
EncryptedMessage.h:13: error: expected ')' before 'fin'
This one I think is because you don't write std::ifstream. ifstream, ofstream and all the things in the standard library is defined in the std namespace, that's why you write std:: infront.

You also need to put ; after the method declarations.
Fire Boar
You're missing a lot of semicolons in the header file there.
snowboardalliance
Fire Boar wrote:
You're missing a lot of semicolons in the header file there.


Such as the one on the VERY LAST LINE.

That's a commonly missed syntax error which will produce confusing error output to a novice.


As others have stated, the first error says that the compiler can't find your base class and you should ensure it is defined in Message.h (and check the semicolon there too).
Related topics
Programming Help & Support Guidelines
The Inheritance Trilogy
Bible Verses: Do Disbelievers Go To Hell?
Destiny - " Trouble with the rat race..."
PHP script trouble
The story of Shut Up, Manner, and Trouble
having trouble scoring on frihost?
Trouble limite de la personalité
Trouble logging in: user sonlight
Email Trouble - Automatic spam filters?
The New World (A.K.A. North and South America)
Trouble with submitting an integer to MySQL
Harry Potter 5 (own written version)
Trouble with girl
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.