virtual bool error C4430

Hello there!

Thanks for visiting my topic, to get it straigt, I am seeking for help. Before you ask me: Nope, im not coding since yesterday, yes i googled my problem, yes i asked my mentor for help (he had no clue either) so don't think i want to waste your time or abuse this forum :)

First off I'll show you the problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#ifndef VERGLEICHER_H
#define VERGLEICHER_H
#include "punkt.h"

using namespace std;

class Vergleicher{
public:
	virtual bool kleiner(const Punkt& p1, const Punkt& p2) = 0;
};

#endif /* VERGLEICHER_H */


this class was intented to inherit the function kleiner ( this means smaller) to 3 other classes but unfortunatley I get this error:

"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"

Here are some things I already tried to fix this problem:

-remove #pragma from code
-remove function arguments (this was a bad idea)
-remove all commands to the compiler
-write the class in the same .h than the other 3 classes
-delete and rewrite the class
-adding/removing namespace std (no effect at all)
-switching (const Punkt& p1 ....) to (Punkt p1, ...)
-trying to use a virtual int instead of a virtual bool (got same error)
-trying to use no virtual class at all (still same error?!?!?!?!)
-writing the code on a friends laptop with another version of Visual Studio
-google it
-google it again
-annoy my friends to help me
-annoy my mentor to help me
-google it again


########################################################
############ SOLUTION ##################################
########################################################

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#ifndef VERGLEICHER_H
#define VERGLEICHER_H

struct Punkt {                                                     //I declared this struct here instead 
    int x, y;                                                           //of using compiler orders
};

class Vergleicher{
public:
	virtual bool kleiner(Punkt& p1,Punkt& p2) = 0;   // <- they are not const any longer!
};

#endif /* VERGLEICHER_H */ 


Now if u think its a problem that point p1 and p2 are not const anylonger, dont be worried! When inheriting the abstract class (Yep thats the WHOLE class) u can add "const" again and he wont overwrite/reinterpret the method!

Thanks for everyone who helped me to figure this finally out:

Branflakes91093
TheIdeasMan
Disch

Have a great weekend gentlemen :)
Last edited on
The compiler doesn't know what Punkt is.
Do you need to include the header file that declares the class Punkt?

The type Punkt is not defined in your code, you must define types for parameters in a function declaration.

Also try to avoid using namespace std; - it brings in lots of stuff into the global namespace, and can cause conflicts in names of variables & functions.

Either put std:: before each std thing. I do this for things which are frequently used in a file - for example if I use std::find once or twice.

Or you can have a using std::cout; statement say, for things which are used a lot.

HTH
I'm sorry, I accidentally posted the wrong version of the code :(
thanks for the quick answer tho!
I updated my post now ;)
And you still have problems? Can you post the actual error in full?
It might be a circular dependency.

Does punkt.h include vergleiche.h? If yes, you have a problem.

To solve, do not include punkt.h from the header file. Instead, just forward declare the class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#pragma once
#ifndef VERGLEICHER_H
#define VERGLEICHER_H


//#include "punkt.h"  <-  bad.  Move this to the cpp file, not the h file
class Punkt;  // <- good

using namespace std;



class Vergleicher{
public:
	virtual bool kleiner(const Punkt& p1, const Punkt& p2) = 0;
};

#endif /* VERGLEICHER_H */ 
Sadly I have :(
The Compiler says:



Fehler 1 error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C++ nicht unterst├╝tzt. c:\users\tim\downloads\vergleicher.h 10 1 Praktikum13-1-20



(translated:

Error 1 error C4430: missing typespecifier - int assumed. Note: C++ does not support default-int". (....)
)
if it helps I can also post other classes and stuff, but I dont think it will help a lot, the std::stuff is a good idea for the rest of the code, but here I didnt want to have any output at all so i dont know if it helps.
Thanks a lot tho :)
Hello Disch,
thanks for the quick answer, I tried to declare the struct Punkt (For some reason it HAS to be a struct, this was one of the tasks [which is totally pointless I think]) like u said, I still get the same error and my compiler doesn't seem to find any other problems :/
Yeah the std:: stuff doesn't have anything to do with your problem, I just try to break people out of their bad habits early (not that it is your fault - there is lots of code on the net has using namespace std;, even Bjarne Stoustrup does it :D)

I don't have any other suggestions, so will have to leave you in the very good hands of Disch, who has vastly more experience than me.
Last edited on
Can you show me 2 more things?:

1) punkt.h

2) copy/paste of the #include lines in whatever cpp file is causing this error (not the header).
GOOD NEWS ********************

it works! I did what Disch told me (declare: struct Punkt;) on top of the abstract class
and then just removed "const" from the argument list!
I don't really know why this works, but I am currently the happiest man on earth!!! :)

I will edit my post now and add a solution, so everybody can see it on the first post, thank you guys so much!!!
Topic archived. No new replies allowed.