By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,206 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,206 IT Pros & Developers. It's quick & easy.

Abstract-Class Problem

P: n/a
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::output(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

Aug 15 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
silversurfer2025 wrote:
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) {
void used(Test & tmp) { // More like that in C++ ...
std::cout << "call from using..";
tmp->first();
tmp.first();
}
};

int main (int argc, char * const argv[]) {
Test_child tst;
Using u;
u.use(&tst);
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();
Note: this function is *not* virtual, nor inline, thus you will need to
compile framework.cpp
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"
It is bad practice to put upper-case in include names as it tend to
change when you go from one system to another ... (just a
recommendation, I recently had another case-hell because of that ...)
>
class FrameWork_GUI : public FrameWork{
void output(int type, std::string);
};

#endif /*_FrameWork_GUI_*/

Child-Class-Cpp:
#include "FrameWork_GUI.h"

void FrameWork_GUI::output(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 FrameWork;
class ModelContainer {
public:
ModelContainer(FrameWork* crd2);
private:
FrameWork* crd;
};
Usage-Class-Cpp:
#include "FrameWork.h"
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..
Yes, you need FrameWork.o as not all the methods are pure virtual ...
>
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
Pierre
Aug 15 '06 #2

P: n/a

Pierre Barbier de Reuille wrote:
silversurfer2025 wrote:
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) {
void used(Test & tmp) { // More like that in C++ ...
std::cout << "call from using..";
tmp->first();
tmp.first();
}
};

int main (int argc, char * const argv[]) {
Test_child tst;
Using u;
u.use(&tst);
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();

Note: this function is *not* virtual, nor inline, thus you will need to
compile framework.cpp
Thanks for the hint. It is pretty obvious now that you say it ;)
>
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"

It is bad practice to put upper-case in include names as it tend to
change when you go from one system to another ... (just a
recommendation, I recently had another case-hell because of that ...)
Thanks a lot, I will change all headers... I did not know it could lead
to problems..

class FrameWork_GUI : public FrameWork{
void output(int type, std::string);
};

#endif /*_FrameWork_GUI_*/

Child-Class-Cpp:
#include "FrameWork_GUI.h"

void FrameWork_GUI::output(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 FrameWork;
What does this mean? Do I have to add this line somewhere in the class
"ModelContainer.h"? If yes, then why?
>
class ModelContainer {
public:
ModelContainer(FrameWork* crd2);
private:
FrameWork* crd;
};
Usage-Class-Cpp:

#include "FrameWork.h"
This is in the original file, I just made a copy-and-paste error. It is
in all files which use it!
>
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..

Yes, you need FrameWork.o as not all the methods are pure virtual ...
OK, I changed the Makefile to include FrameWork.o, the includes are in
all the Files using the FrameWork-class and I still get the errors
telling me that " ISO C++ forbids declaration of 'FrameWork' with
no type"

What does the line
class FrameWork;
mean? Where and why should I put it?

Thanks a lot once more,...
Tim

Aug 15 '06 #3

P: n/a
silversurfer2025 wrote:
Pierre Barbier de Reuille wrote:
>silversurfer2025 wrote:
>>Hello everyone,
[...]
>>>
Usage-Class-Header (ModelContainer):
class FrameWork;
What does this mean? Do I have to add this line somewhere in the class
"ModelContainer.h"? If yes, then why?
Yes, you need to put it in ModelContainer.h *before* the definition of
the class ModelContainer.
This statement simply tells the compiler that a class named FrameWork
does exists somewhere in that namespace, but you don't want to give him
the complete definition right now (it is called forward declaration). If
what you need of a class is only a pointer or reference, that's all you
need to make your code work.
>
>>class ModelContainer {
public:
ModelContainer(FrameWork* crd2);
private:
FrameWork* crd;
};
Usage-Class-Cpp:
#include "FrameWork.h"
This is in the original file, I just made a copy-and-paste error. It is
in all files which use it!
>>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..
Yes, you need FrameWork.o as not all the methods are pure virtual ...

OK, I changed the Makefile to include FrameWork.o, the includes are in
all the Files using the FrameWork-class and I still get the errors
telling me that " ISO C++ forbids declaration of 'FrameWork' with
no type"

What does the line
class FrameWork;
mean? Where and why should I put it?

Thanks a lot once more,...
Tim
Aug 15 '06 #4

P: n/a
Yes, you need to put it in ModelContainer.h *before* the definition of
the class ModelContainer.
This statement simply tells the compiler that a class named FrameWork
does exists somewhere in that namespace, but you don't want to give him
the complete definition right now (it is called forward declaration). If
what you need of a class is only a pointer or reference, that's all you
need to make your code work.
Wonderful, the error in most of the cases was the circle-include.
However, the first compiler error is not created by such a mistake...
If it is okay, I am giving the class declaration and definition once
more here:

------------------------------------------
FrameWork.h:
#ifndef _framework_
#define _framework_

#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include "FeatureVector.h"
#include "ModelContainer.h"
#include "FeatureExtraction.h"
#include "HebbConnections.h"
#include "ModelContainer.h"
#include "ImageHandler.h"
#include "./Fundamental/ConfigReader.h"
#include "./ImageProcessing/Formation/YUVImage.h"
#include "./Structures/TribotsException.h"
#include "iGRLVQ.h"
#include "PostProcessing.h"

class FrameWork {
public:
void init();
virtual void output(int type, std::string) = 0;

private:
HebbConnections* hebb;
ModelContainer* models;
ModelContainer* trainData;
ModelContainer* testData;
FeatureExtraction* extractor;

ImageHandler* ih;
FeatureVector* extracted;
YUVImage* currentImage;
iGRLVQ* learner;

std::map<int, std::stringindexImageMap;
};

#endif /*_FrameWork_*/
------------------------------------------
FrameWork.cpp:
#include "FrameWork.h"

void FrameWork::init() {
extractor = new FeatureExtraction(this);
hebb = new HebbConnections(this);
models = new ModelContainer(this);
trainData = new ModelContainer(this);
testData = new ModelContainer(this);
ih = new ImageHandler(this);
learner = new iGRLVQ(this,models,NULL);
}
------------------------------------------
FrameWorkGUI.h:
#ifndef _framework_gui_
#define _framework_gui_

#include <iostream>
#include "FrameWork.h"

class FrameWork_GUI : public FrameWork {
void output(int type, std::string);
};

#endif /*_FrameWork_GUI_*/

------------------------------------------
FrameWorkGUI.cpp:
#include "FrameWork_GUI.h"

void FrameWork_GUI::output(int type, std::string str) {
std::cout << "test";
}

Unfortunately the compiler error is still
FrameWork_GUI.h:12: error: expected class-name before '{' token

So why the heck is the FrameWorkGU not finding FrameWork?

Thanks, I honestly would have not thought of forward declaration...
well seems I am quite a beginner ;)

Tim

Aug 15 '06 #5

P: n/a
silversurfer2025 wrote:
>Yes, you need to put it in ModelContainer.h *before* the definition
of the class ModelContainer.
This statement simply tells the compiler that a class named FrameWork
does exists somewhere in that namespace, but you don't want to give
him the complete definition right now (it is called forward
declaration). If what you need of a class is only a pointer or
reference, that's all you need to make your code work.

Wonderful, the error in most of the cases was the circle-include.
However, the first compiler error is not created by such a mistake...
If it is okay, I am giving the class declaration and definition once
more here:

------------------------------------------
FrameWork.h:
#ifndef _framework_
#define _framework_
First off, names that begin with an underscore in the global namespace
(and that includes macro names) are reserved by the implementation, so
drop the leading underscores here and invent some more meaningful name,
like 'FrameWork_h_included'. Make sure the spelling is the same every
time you're using it.
>
#include <string>
#include <map>
OK.
#include <iostream>
#include <fstream>
I don't see anything from those two headers used here. Why do you think
you need to include them?
#include "FeatureVector.h"
#include "ModelContainer.h"
#include "FeatureExtraction.h"
#include "HebbConnections.h"
#include "ModelContainer.h"
#include "ImageHandler.h"
#include "./Fundamental/ConfigReader.h"
#include "./ImageProcessing/Formation/YUVImage.h"
#include "./Structures/TribotsException.h"
#include "iGRLVQ.h"
#include "PostProcessing.h"
I don't think you really need these here. If your class only has
declarations of pointers to those types, you're much better off
forward-declaring them all instead of including their respective
headers.
>
class FrameWork {
public:
void init();
virtual void output(int type, std::string) = 0;
Passing objects is better by reference to const...
>
private:
HebbConnections* hebb;
ModelContainer* models;
ModelContainer* trainData;
ModelContainer* testData;
FeatureExtraction* extractor;

ImageHandler* ih;
FeatureVector* extracted;
YUVImage* currentImage;
iGRLVQ* learner;
As it turns out below, you're managing your own dynamic memory.
Read up on "The Rule of Three" and follow it.

Also, if your class is intended to be deleted polymorphically, you
should think of making the destructor virtual.
>
std::map<int, std::stringindexImageMap;
};

#endif /*_FrameWork_*/
The comment doesn't match the symbol name. Beware.
------------------------------------------
FrameWork.cpp:
#include "FrameWork.h"
Here you might actually need to include all headers because you
are initialising those objects here and the compiler needs to know
the definition of the classes.
>
void FrameWork::init() {
extractor = new FeatureExtraction(this);
hebb = new HebbConnections(this);
models = new ModelContainer(this);
trainData = new ModelContainer(this);
testData = new ModelContainer(this);
ih = new ImageHandler(this);
learner = new iGRLVQ(this,models,NULL);
}
------------------------------------------
FrameWorkGUI.h:
#ifndef _framework_gui_
#define _framework_gui_
Again, same message about the leading underscore and a more meaningful
name, like "FrameWorkGUI_h_included".
>
#include <iostream>
You don't seem to be using anything defined in that header, why include
it at all?
#include "FrameWork.h"

class FrameWork_GUI : public FrameWork {
void output(int type, std::string);
};

#endif /*_FrameWork_GUI_*/

------------------------------------------
FrameWorkGUI.cpp:
#include "FrameWork_GUI.h"
The name of this header does NOT match the name you just wrote above
when showing the contents of the file. This one has an extra '_' in
it. Make sure you're including the right file. Clean up your project
by throwing away what is not needed.
>
void FrameWork_GUI::output(int type, std::string str) {
std::cout << "test";
Now, *here* you're using 'std::cout', but this file does not include
the <iostream(by itself). It should. You should *not* rely on your
headers including other headers. All necessary headers must be here
in the same source file, so we can easily understand what is used and
where.
}

Unfortunately the compiler error is still
FrameWork_GUI.h:12: error: expected class-name before '{' token

So why the heck is the FrameWorkGU not finding FrameWork?

Thanks, I honestly would have not thought of forward declaration...
well seems I am quite a beginner ;)
I don't see any forward-declarations in your code you posted here.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 15 '06 #6

P: n/a

"silversurfer2025" <ki****@web.dewrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
>Yes, you need to put it in ModelContainer.h *before* the definition of
the class ModelContainer.
This statement simply tells the compiler that a class named FrameWork
does exists somewhere in that namespace, but you don't want to give him
the complete definition right now (it is called forward declaration). If
what you need of a class is only a pointer or reference, that's all you
need to make your code work.

Wonderful, the error in most of the cases was the circle-include.
However, the first compiler error is not created by such a mistake...
If it is okay, I am giving the class declaration and definition once
more here:

------------------------------------------
FrameWork.h:
#ifndef _framework_
#define _framework_
I'm not positive, but I seem to recall that you shouldn't have leading or
tailing underscores in your include guards. (Someone else can cite chapter
and verse from the Standard, I'm sure.)
>
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include "FeatureVector.h"
#include "ModelContainer.h"
#include "FeatureExtraction.h"
#include "HebbConnections.h"
#include "ModelContainer.h"
#include "ImageHandler.h"
#include "./Fundamental/ConfigReader.h"
#include "./ImageProcessing/Formation/YUVImage.h"
#include "./Structures/TribotsException.h"
#include "iGRLVQ.h"
#include "PostProcessing.h"
Since you're using pointers to most of the types in the files above, you
might want to consider just forward-declaring the types here, and putting
the #include statements in the .cpp file instead. It's cleaner that way,
and you have fewer dependencies when including this header in other files.
(Besides, this is what led to your circular-inclusion problems in the first
place, right? :-))
class FrameWork {
public:
void init();
virtual void output(int type, std::string) = 0;

private:
HebbConnections* hebb;
ModelContainer* models;
ModelContainer* trainData;
ModelContainer* testData;
FeatureExtraction* extractor;

ImageHandler* ih;
FeatureVector* extracted;
YUVImage* currentImage;
iGRLVQ* learner;

std::map<int, std::stringindexImageMap;
};

#endif /*_FrameWork_*/
------------------------------------------
FrameWork.cpp:
#include "FrameWork.h"

void FrameWork::init() {
extractor = new FeatureExtraction(this);
hebb = new HebbConnections(this);
models = new ModelContainer(this);
trainData = new ModelContainer(this);
testData = new ModelContainer(this);
ih = new ImageHandler(this);
learner = new iGRLVQ(this,models,NULL);
}
------------------------------------------
FrameWorkGUI.h:
Is that name correct? You're including "FrameWork_GUI.h". Do you have two
versions in your project directory?
#ifndef _framework_gui_
#define _framework_gui_

#include <iostream>
#include "FrameWork.h"

class FrameWork_GUI : public FrameWork {
Is this line 12, where the error is reported?
void output(int type, std::string);
};

#endif /*_FrameWork_GUI_*/

------------------------------------------
FrameWorkGUI.cpp:
#include "FrameWork_GUI.h"

void FrameWork_GUI::output(int type, std::string str) {
std::cout << "test";
}

Unfortunately the compiler error is still
FrameWork_GUI.h:12: error: expected class-name before '{' token
What's line 12?
>
So why the heck is the FrameWorkGU not finding FrameWork?
Are there other errors? Someimes, if there is an error in compiling a
header, then errors are reported in units which include that header, and
those errors may be reported first (oddly enough).

Also, you might try cleaning and re-building the whole project, to be sure
the compiler is seeing the latest information. (Just a thought. VC++, at
least, seems to get screwed up sometimes when changing headers.)

-Howard
Aug 15 '06 #7

P: n/a
First of all, thanks everybody, specially Howard and Victor for
helping. i am honestly very happy to have your suggestions and hints on
better coding, I am happy I can learn a lot this way!

Howard, wrote:
"silversurfer2025" <ki****@web.dewrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Yes, you need to put it in ModelContainer.h *before* the definition of
the class ModelContainer.
This statement simply tells the compiler that a class named FrameWork
does exists somewhere in that namespace, but you don't want to give him
the complete definition right now (it is called forward declaration). If
what you need of a class is only a pointer or reference, that's all you
need to make your code work.
Wonderful, the error in most of the cases was the circle-include.
However, the first compiler error is not created by such a mistake...
If it is okay, I am giving the class declaration and definition once
more here:

------------------------------------------
FrameWork.h:
#ifndef _framework_
#define _framework_

I'm not positive, but I seem to recall that you shouldn't have leading or
tailing underscores in your include guards. (Someone else can cite chapter
and verse from the Standard, I'm sure.)
It will be changed... I took this habit from some other code and
thought it was standard,...

>

#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include "FeatureVector.h"
#include "ModelContainer.h"
#include "FeatureExtraction.h"
#include "HebbConnections.h"
#include "ModelContainer.h"
#include "ImageHandler.h"
#include "./Fundamental/ConfigReader.h"
#include "./ImageProcessing/Formation/YUVImage.h"
#include "./Structures/TribotsException.h"
#include "iGRLVQ.h"
#include "PostProcessing.h"

Since you're using pointers to most of the types in the files above, you
might want to consider just forward-declaring the types here, and putting
the #include statements in the .cpp file instead. It's cleaner that way,
and you have fewer dependencies when including this header in other files.
(Besides, this is what led to your circular-inclusion problems in the first
place, right? :-))
Yes, you are right :( It will as well be changed... But at least the
error does not seem to come from here..

>
class FrameWork {
public:
void init();
virtual void output(int type, std::string) = 0;

private:
HebbConnections* hebb;
ModelContainer* models;
ModelContainer* trainData;
ModelContainer* testData;
FeatureExtraction* extractor;

ImageHandler* ih;
FeatureVector* extracted;
YUVImage* currentImage;
iGRLVQ* learner;

std::map<int, std::stringindexImageMap;
};

#endif /*_FrameWork_*/
------------------------------------------
FrameWork.cpp:
#include "FrameWork.h"

void FrameWork::init() {
extractor = new FeatureExtraction(this);
hebb = new HebbConnections(this);
models = new ModelContainer(this);
trainData = new ModelContainer(this);
testData = new ModelContainer(this);
ih = new ImageHandler(this);
learner = new iGRLVQ(this,models,NULL);
}
------------------------------------------
FrameWorkGUI.h:

Is that name correct? You're including "FrameWork_GUI.h". Do you have two
versions in your project directory?
Sorry, it is a typo. The file is named FrameWork_GUI.h and so is the
include...

>
#ifndef _framework_gui_
#define _framework_gui_

#include <iostream>
#include "FrameWork.h"

class FrameWork_GUI : public FrameWork {

Is this line 12, where the error is reported?
Yes, the erroneous line is the one class FrameWork_GUI... (the first
usage of FrameWork in this file)

>
void output(int type, std::string);
};

#endif /*_FrameWork_GUI_*/

------------------------------------------
FrameWorkGUI.cpp:
#include "FrameWork_GUI.h"

void FrameWork_GUI::output(int type, std::string str) {
std::cout << "test";
}

Unfortunately the compiler error is still
FrameWork_GUI.h:12: error: expected class-name before '{' token

What's line 12?
class FrameWork_GUI : public FrameWork {

>

So why the heck is the FrameWorkGU not finding FrameWork?

Are there other errors? Someimes, if there is an error in compiling a
header, then errors are reported in units which include that header, and
those errors may be reported first (oddly enough).
There is no other error... This is (currently) the only one ;)
>
Also, you might try cleaning and re-building the whole project, to be sure
the compiler is seeing the latest information. (Just a thought. VC++, at
least, seems to get screwed up sometimes when changing headers.)
I did, and it did not help.
>

Thanks once more..
Tim

Aug 15 '06 #8

P: n/a
silversurfer2025 wrote:
[..]
Howard, wrote:
>"silversurfer2025" <ki****@web.dewrote in message
news:11*********************@b28g2000cwb.googlegr oups.com...
>>[..]
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include "FeatureVector.h"
#include "ModelContainer.h"
#include "FeatureExtraction.h"
#include "HebbConnections.h"
#include "ModelContainer.h"
#include "ImageHandler.h"
#include "./Fundamental/ConfigReader.h"
#include "./ImageProcessing/Formation/YUVImage.h"
#include "./Structures/TribotsException.h"
#include "iGRLVQ.h"
#include "PostProcessing.h"

Since you're using pointers to most of the types in the files above,
you might want to consider just forward-declaring the types here,
and putting the #include statements in the .cpp file instead. It's
cleaner that way, and you have fewer dependencies when including
this header in other files. (Besides, this is what led to your
circular-inclusion problems in the first place, right? :-))

Yes, you are right :( It will as well be changed... But at least the
error does not seem to come from here..
My *guess* would be that it does. Imagine that in one of those files
you (mistakenly, of course) left the same macro used in #ifndef as in
the "FrameWork.h" file. What would happen? Who knows? With so many
headers apparently including each other for no particular reason, and
applying double inclusion guards possibly at the wrong time, anything
can happen.

Drop all unnecessary includes, or start fresh, and only use forward
declarations. Only include when you really need to (like in the case
with deriving from FrameWork, you do need to give the class FrameWork
definition to the compiler). You will eventually create a network of
classes light enough to be manageable.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 15 '06 #9

P: n/a

Victor Bazarov wrote:
silversurfer2025 wrote:
[..]
Howard, wrote:
"silversurfer2025" <ki****@web.dewrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
[..]
#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include "FeatureVector.h"
#include "ModelContainer.h"
#include "FeatureExtraction.h"
#include "HebbConnections.h"
#include "ModelContainer.h"
#include "ImageHandler.h"
#include "./Fundamental/ConfigReader.h"
#include "./ImageProcessing/Formation/YUVImage.h"
#include "./Structures/TribotsException.h"
#include "iGRLVQ.h"
#include "PostProcessing.h"
Since you're using pointers to most of the types in the files above,
you might want to consider just forward-declaring the types here,
and putting the #include statements in the .cpp file instead. It's
cleaner that way, and you have fewer dependencies when including
this header in other files. (Besides, this is what led to your
circular-inclusion problems in the first place, right? :-))
Yes, you are right :( It will as well be changed... But at least the
error does not seem to come from here..

My *guess* would be that it does. Imagine that in one of those files
you (mistakenly, of course) left the same macro used in #ifndef as in
the "FrameWork.h" file. What would happen? Who knows? With so many
headers apparently including each other for no particular reason, and
applying double inclusion guards possibly at the wrong time, anything
can happen.
Oh Victor, you are so right... Naturally it was another circle-include
I put in there for testing reasons and forgot to delete...
>
Drop all unnecessary includes, or start fresh, and only use forward
declarations. Only include when you really need to (like in the case
with deriving from FrameWork, you do need to give the class FrameWork
definition to the compiler). You will eventually create a network of
classes light enough to be manageable.
I will work over the files once more managing the include files and
putting them into the right place.I started putting all needed includes
into the header file because I read in a tutorial that this was good
programming practice because all includes would be in the same place..
I seem to read the wrong sources don't I?

Seems to be solved right now, thanks a lot once more and greetings from
rainy Germany
Tim
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 15 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.