0

I have a superclass Letter.h

#ifndef LETTER_H  //I have tried ifdef but it give me list of undefined reference 
and variables out of scope 
#define LETTER_H


#include "A.h"

using namespace std;


class Letter{
//variables are declared in protected

public:
        Letter();
        Letter(string,bool);
            };
            #endif

I have a sub class A.h

 #ifndef A_H
    #define A_H
    #include "Letter.h"
    using namespace std;



 class A: public Letter{
    //variables are declared in private
    public:
        A();
        A(string, bool, int, int, double);   
 };
       #endif

In my Letter.cpp I have #include Letter.h In my A.cpp I have #include A.h and #include Letter.h

In my A.cpp

   A::A(string ShapeName, bool warpspace, int xval, int yval, double areas):Letter(ShapeName, warpspace)
{
    xVal = xval;
    yVal = yval;
    area = areas;
}

In my letter.cpp

Letter::Letter (string name, bool containsWarpSpace)
{
    this->name = name;
    this->containsWarpSpace = containsWarpSpace;
}

when I compile the above like this: g++ Letter.cpp Letter.h A.cpp A.h it gives me error: expected class-name before ‘{’ token {

I know letter is the parent class it does not need to include the sub class but however when I remove the #include square.h it gives me relocation invalid symbol index error .

Is the guard and header files properly included this way?

Lets say if i haven't wrote anything to inherit from Letter yet , will the compiler still allow me to compile?

  • 2
    You are missing a semi-colon ";" at the end of declaration of class A – 10100111001 Oct 27 '16 at 07:57
  • 1
    Aren't you missing something when ending the `A` class? You have the closing brace `}`, but shouldn't there be something else? – Some programmer dude Oct 27 '16 at 07:58
  • 1
    @10100111001 Spoiler alert – Treycos Oct 27 '16 at 07:58
  • 1
    Also, don't ever use `using` to import names from or namespaces themselves. Name collisions will ensue sooner or later. If not in your own code, someone using your code will get really really **. – rubenvb Oct 27 '16 at 08:04
  • @10100111001 I have added it in , I forgot to type it in sorry . the org code was with " ; " – forgivenprog33442 Oct 27 '16 at 08:06
  • @forgivenprog33442 There's no way to diagnose your error from your example code. Provide a [MCVE] that reproduces it. – πάντα ῥεῖ Oct 27 '16 at 08:13
  • The code is long with accessors and mutators and calcluations but i haven't wrote anything to inherit the parent class functions and variables , but is there anything wrong with the above example first? am i doing it correctly? I don't wanna post a code overlapping issues with the #include guards and #include header files . i need to make sure the headers and guards are correctly included @πάνταῥεῖ – forgivenprog33442 Oct 27 '16 at 09:18
  • @πάνταῥεῖ have edited to make it minimal – forgivenprog33442 Oct 28 '16 at 03:40

0 Answers0