S
silversurfer2025
Hello everyone,
I am currently having problems with a C++ abstract class. I have a
class FrameWork.h which defines some methods (of which some are
abstract, i.e. virtual void method() = 0). In FrameWork.cpp I define
some of the methods while I naturally leave the abstract methods
undefined. Now I wrote a class FrameWork_GUI.h which inherits from the
abstract FrameWork class and implements the missing (so far abstract)
methods. Furthermore, I would like to define some methods in other
classes, which expect an object of the base-class-type. So far so good.
In order to be sure that something like this was working the way i
thought it could work, I tried all this in a small test-class where it
worked perfectly well. However, in my real application I get the
compiler error telling me that
"error: expected `)' before '*' token" together with
"error: ISO C++ forbids declaration of 'FrameWork' with no
type" and later on
"error: 'FrameWork' has not been declared"
so I guess it should only be a minor problem here. I checked the
inlcudes and they should be fine...
OK, here are the classes which work:
Base-Class:
#ifndef _test_
#define _test_
#include <iostream>
class Test {
public:
virtual void first() =0;
void second() {
std::cout << "second Method\n";
}
};
#endif
Child-Class:
#ifndef _test_child_
#define _test_child_
#include "test.cpp"
class Test_child : public Test {
public:
void first() {
std::cout << "first\n";
}
};
#endif
The class usig the base-class in a method parameter:
#include "test.cpp"
#include "test_child.cpp"
#include <iostream>
class Using{
public:
void use(Test* tmp) {
std::cout << "call from using..";
tmp->first();
}
};
int main (int argc, char * const argv[]) {
Test_child tst;
Using u;
u.use(&tst);
}
--------------------------------------------------------------------------
Now let's come to my problem-children of today:
Base-Class-Header:
#ifndef _FrameWork_
#define _FrameWork_
#include <iostream>
#include <fstream>
class FrameWork{
public:
void init();
virtual void output(int type, std::string) = 0;
private:
ModelContainer* models;
};
#endif /*_FrameWork_*/
Base-Class-Cpp:
#include "FrameWork.h"
void FrameWork::init() {
models = new ModelContainer(this);
std::cout << "initializing";
}
////////////////////////////////////////////
Child-Class-Header:
#ifndef _FrameWork_GUI_
#define _FrameWork_GUI_
#include "FrameWork.h"
class FrameWork_GUI : public FrameWork{
void output(int type, std::string);
};
#endif /*_FrameWork_GUI_*/
Child-Class-Cpp:
#include "FrameWork_GUI.h"
void FrameWork_GUI:utput(int type, std::string str) {
std::cout << str;
}
// OK, the class ModelContainer is waiting for a FrameWork-Object in
its Constructor.
// The errors I get during compiling relate to this class exactly there
where I use the FrameWork-object
// and tell me that FrameWork would not be defined.
Usage-Class-Header (ModelContainer):
class ModelContainer {
public:
ModelContainer(FrameWork* crd2);
private:
FrameWork* crd;
};
Usage-Class-Cpp:
ModelContainer::ModelContainer(FrameWork* crd2) {
crd=crd2;
}
OK, last thing here would be the relevant part of my Makefile. Do I
need the FrameWork.o in there as well? I was not sure because it was
abstract.. However, if I put it in there or not.. I get the same
errors..
ADDOBJS= FrameWork_GUI.o \
ModelContainer.o
LDFLAGS = -lraw1394 -ldc1394_control -ljpeg
main:main.o $(ADDOBJS)
@g++ -o main $(LDFLAGS) $+
Ok, this should be everything. I tried to give you as much code as
needed, hopefully it is enough.
Hope you guys can help, I have been struggling with all this for quite
some time..
Greetings and thanks a lot in advance
Tim
I am currently having problems with a C++ abstract class. I have a
class FrameWork.h which defines some methods (of which some are
abstract, i.e. virtual void method() = 0). In FrameWork.cpp I define
some of the methods while I naturally leave the abstract methods
undefined. Now I wrote a class FrameWork_GUI.h which inherits from the
abstract FrameWork class and implements the missing (so far abstract)
methods. Furthermore, I would like to define some methods in other
classes, which expect an object of the base-class-type. So far so good.
In order to be sure that something like this was working the way i
thought it could work, I tried all this in a small test-class where it
worked perfectly well. However, in my real application I get the
compiler error telling me that
"error: expected `)' before '*' token" together with
"error: ISO C++ forbids declaration of 'FrameWork' with no
type" and later on
"error: 'FrameWork' has not been declared"
so I guess it should only be a minor problem here. I checked the
inlcudes and they should be fine...
OK, here are the classes which work:
Base-Class:
#ifndef _test_
#define _test_
#include <iostream>
class Test {
public:
virtual void first() =0;
void second() {
std::cout << "second Method\n";
}
};
#endif
Child-Class:
#ifndef _test_child_
#define _test_child_
#include "test.cpp"
class Test_child : public Test {
public:
void first() {
std::cout << "first\n";
}
};
#endif
The class usig the base-class in a method parameter:
#include "test.cpp"
#include "test_child.cpp"
#include <iostream>
class Using{
public:
void use(Test* tmp) {
std::cout << "call from using..";
tmp->first();
}
};
int main (int argc, char * const argv[]) {
Test_child tst;
Using u;
u.use(&tst);
}
--------------------------------------------------------------------------
Now let's come to my problem-children of today:
Base-Class-Header:
#ifndef _FrameWork_
#define _FrameWork_
#include <iostream>
#include <fstream>
class FrameWork{
public:
void init();
virtual void output(int type, std::string) = 0;
private:
ModelContainer* models;
};
#endif /*_FrameWork_*/
Base-Class-Cpp:
#include "FrameWork.h"
void FrameWork::init() {
models = new ModelContainer(this);
std::cout << "initializing";
}
////////////////////////////////////////////
Child-Class-Header:
#ifndef _FrameWork_GUI_
#define _FrameWork_GUI_
#include "FrameWork.h"
class FrameWork_GUI : public FrameWork{
void output(int type, std::string);
};
#endif /*_FrameWork_GUI_*/
Child-Class-Cpp:
#include "FrameWork_GUI.h"
void FrameWork_GUI:utput(int type, std::string str) {
std::cout << str;
}
// OK, the class ModelContainer is waiting for a FrameWork-Object in
its Constructor.
// The errors I get during compiling relate to this class exactly there
where I use the FrameWork-object
// and tell me that FrameWork would not be defined.
Usage-Class-Header (ModelContainer):
class ModelContainer {
public:
ModelContainer(FrameWork* crd2);
private:
FrameWork* crd;
};
Usage-Class-Cpp:
ModelContainer::ModelContainer(FrameWork* crd2) {
crd=crd2;
}
OK, last thing here would be the relevant part of my Makefile. Do I
need the FrameWork.o in there as well? I was not sure because it was
abstract.. However, if I put it in there or not.. I get the same
errors..
ADDOBJS= FrameWork_GUI.o \
ModelContainer.o
LDFLAGS = -lraw1394 -ldc1394_control -ljpeg
main:main.o $(ADDOBJS)
@g++ -o main $(LDFLAGS) $+
Ok, this should be everything. I tried to give you as much code as
needed, hopefully it is enough.
Hope you guys can help, I have been struggling with all this for quite
some time..
Greetings and thanks a lot in advance
Tim