c++ - error C3646: unknown override specifier - c++

I modified my project and after compiling there pop up some weird error.
#ifndef BART_RAY_TRACER_MESH_H
#define BART_RAY_TRACER_MESH_H
#include <vector>
#include "assert.h"
#include "vec3f.h"
class Triangle;
class Mesh {
public:
uint32_t nverts;
bool _is_static;
vec3f *verts;
vec3f *_verts_world;
Material material;
// 2 error occurs at the line below
Matrix4x4 _trans_local_to_world; // '_trans_local_to_world': unknown override specifier & missing type specifier - int assumed. Note: C++ does not support default-int
Matrix4x4 _trans_local_to_world_inv;
TransformHierarchy *_trans_hierarchy;
std::vector<Triangle* > triangles;
// ...
};
#endif
When I change the order of the declaration a little bit, the error always occurs the line after Material material, but with different message:
#ifndef BART_RAY_TRACER_MESH_H
#define BART_RAY_TRACER_MESH_H
#include <vector>
#include "assert.h"
#include "vec3f.h"
class Triangle;
class Mesh {
public:
uint32_t nverts;
bool _is_static;
vec3f *verts;
vec3f *_verts_world;
Material material;
// 2 error occurs at the line below
TransformHierarchy *_trans_hierarchy; // error C2143: syntax error: missing ';' before '*' & error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Matrix4x4 _trans_local_to_world;
Matrix4x4 _trans_local_to_world_inv;
std::vector<Triangle* > triangles;
// ...
};
#endif
I've searched for similar questions on SO but none seems useful.
I've checked my vec3f, Triangle class definition in case there are missing semicolons but I can't find any.
Can any one help?

This is just another Microsoft cock-up. Here it is in essence:
class C
{
x y ;
} ;
If you submit this to a sensible compiler like g++, it gives you a helpful error message:
3:2: error: 'x' does not name a type
MSVC, on the other hand, comes up with this gibberish:
(3): error C3646: 'y': unknown override specifier
(3): error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
With this key, you can decrypt Microsoft's error message into:
error: 'Matrix4x4' does not name a type

The error is most likely because that TransformHierarchy and Matrix4x4 are not defined.
If they are not defined in "assert.h" and "vec3f.h", this should be the case.
Forward declaration is enough only when you use the reference types and/or pointer types only. Therefore, to forward declare Triangle is OK. But forward declare Triangle does not mean your shape.h is processed. Neither does your material.h which is included in shape.h.
Therefore, all names in material.h is not visible from this code.
TransformHierarchy and Matrix4x4 are not recognized by the compiler.
Many of the compliers will complain with words similar to "missing type specifier - int assumed"

In my case, it was found that a header file had the following directives for a class [ie, myComboBoxData]
#ifndef __COMBOBOXDATA__
#define __COMBOBOXDATA__
// ...
class myComboBoxData
{
// ...
}
#endif
As another class below tried to use myComboBoxData class
class TypeDlg : public CDialog
{
myComboBoxData cbRow,cbCol;
// ...
}
the error message popped up as above:
"error C3646: 'cbRow': unknown override specifier".
Solution:
The problem was the directive name (__COMBOBOXDATA__) was already used by OTHER header.
Thus, make sure to use some other name like (__myCOMBOBOXDATA__).

Related

C++ .h and .cpp file separate

I'm trying to separate my c++ code to one header and one cpp file, but the interpreter showing some errors.
Here is my code:
Password.h:
#ifndef PASSWORD_H
#define PASSWORD_H
class Password {
private:
string aliasName_;
int hashOfPassword_;
public:
void setAliasName(string aliasName);
void setHashOfPassword(int hashOfPassword);
string getAliasName() { return aliasName_; }
int getHashOfPassword() { return hashOfPassword_; }
};
#endif
Password.cpp:
#include <string>
#include "Password.h"
using std::string;
void Password::setAliasName(string aliasName) {
aliasName_ = aliasName;
}
void Password::setHashOfPassword(int hashOfPassword) {
hashOfPassword_ = hashOfPassword;
}
Errors:
Error C2065 'aliasName_': undeclared identifier X\password.cpp 7
Error C2511 'void Password::setAliasName(std::string)': overloaded member function not found in 'Password' X\password.cpp 6
Error C3646 'aliasName_': unknown override specifier X\password.h 6
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int X\password.h 6
Error C2061 syntax error: identifier 'string' X\password.h 9
Error C3646 'getAliasName': unknown override specifier X\password.h 11
Error C2059 syntax error: '(' X\password.h 11
Error C2334 unexpected token(s) preceding '{'; skipping apparent function body X\password.h 11
Anyone have any ideas ?
You need to move using std::string before the declaration of your class:
#ifndef PASSWORD_H
#define PASSWORD_H
#include <string>
using std::string;
class Password {
…
and remove it from your .cpp file.
Also, you might want to use #pragma once instead of the traditional #ifndef/#define/#endif and finally you might want to make your argument and methods const when need be.
You need to move
#include <string>
using std::string;
To inside Password.h, you can then remove these two lines from Password.cpp.
Just add std:: to every string in your header file and remember, you should never use using or using namespace there! You should also include all the headers to the file in which you use them.

Passing template class instance to a constructor of another class

My code:
BlockyWorld.hpp
#ifndef BLOCKYWORLD_H
#define BLOCKYWORLD_H
#include <CImg.h>
namespace logic {
class BlockyWorld {
public:
BlockyWorld( const CImg<float>* heightmap );
};
}
#endif // BLOCKYWORLD_H
BlockyWorld.cpp
#include "BlockyWorld.hpp"
namespace logic {
BlockyWorld::BlockyWorld( const CImg<float>* heightmap ) {}
}
main.cpp
#include <CImg.h>
#include "logic/BlockyWorld.hpp"
//...
CImg<float> heigthMap;
logic::BlockyWorld world( &heigthMap );
//...
I get alot of errors while compiling:
main.cpp:
include\logic\blockyworld.hpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\logic\blockyworld.hpp(9): error C2143: syntax error : missing ',' before '<'
main.cpp(85): error C2664: 'logic::BlockyWorld::BlockyWorld(const logic::BlockyWorld &)' : cannot convert argument 1 from 'cimg_library::CImg<float>' to 'const int'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
BlockyWorld.hpp & cpp
include\logic\blockyworld.hpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\logic\blockyworld.hpp(9): error C2143: syntax error : missing ',' before '<'
include\logic\blockyworld.cpp(4): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
include\logic\blockyworld.cpp(4): error C2143: syntax error : missing ',' before '<'
I don't think it's a circular inclusion error which sometimes causes these kinds of errors for me=).
I must be defining constructor wrong or maybe I'm defining implementation wrong? Was searching for an answer for abount an hour now so I would really use an explanation now.
And just to clarify - I'm not a beginner c/c++ programmer but these templates are confusing :(
Have a nice day and thank your for your answers.
CImg appears to be part of the cimg_library namespace.
Either add using namespace cimg_library to the top of your BlockyWorld.hpp file, or change the function signature to use the namespace like so:
BlockyWorld( const cimg_library::CImg<float>* heightmap );
Along with πάντα ῥεῖ's suggestion of matching up your pointer and reference types.

How to use circularly dependent classes in C++?

This code is not compiling.
What modification can I do to achieve the desired result?
ClassOne.h
#ifndef _CLASS_ONE_
#define _CLASS_ONE_
#include <string>
#include "ClassTwo.h"
class ClassTwo;
class ClassOne
{
private:
string message;
friend ClassTwo;
ClassTwo m_ClassTwo;
public:
ClassOne();
void Display();
};
#endif
ClassTwo.h
#ifndef _CLASS_TWO_
#define _CLASS_TWO_
#include <string>
#include "ClassOne.h"
class ClassOne;
class ClassTwo
{
private:
string message;
friend ClassOne;
ClassOne m_ClassOne;
public:
ClassTwo();
void Display();
};
#endif
ClassOne.cpp
#include "ClassOne.h"
#include "ClassTwo.h"
#include <iostream>
ClassOne :: ClassOne()
{
std::cout<<"ClassOne()...called\n";
this->m_ClassTwo.message = "ClassOne - Message\n";
}
void ClassOne :: Display()
{
std::cout<<this->m_ClassTwo.message;
}
ClassTwo.cpp
#include "ClassTwo.h"
#include "ClassOne.h"
#include <iostream>
ClassTwo :: ClassTwo()
{
std::cout<<"ClassTwo()...called\n";
this->m_ClassOne.message = "ClassTwo - Message\n";
}
void ClassTwo :: Display()
{
std::cout<<this->m_ClassOne.message;
}
main.cpp
#include "ClassOne.h"
#include "ClassTwo.h"
int main()
{
ClassOne one;
one.Display();
ClassTwo two;
two.Display();
}
Error messages
1 error C2146: syntax error : missing ';' before identifier 'message'
2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
4 error C2079: 'ClassTwo::m_ClassOne' uses undefined class 'ClassOne'
5 error C2146: syntax error : missing ';' before identifier 'message'
6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
7 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
8 error C2039: 'message' : is not a member of 'ClassTwo'
9 error C2039: 'message' : is not a member of 'ClassTwo'
10 error C2146: syntax error : missing ';' before identifier 'message'
11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
12 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
13 error C2079: 'ClassOne::m_ClassTwo' uses undefined class 'ClassTwo'
14 error C2146: syntax error : missing ';' before identifier 'message'
15 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
16 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
17 error C2039: 'message' : is not a member of 'ClassOne'
18 error C2039: 'message' : is not a member of 'ClassOne'
19 error C2146: syntax error : missing ';' before identifier 'message'
20 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
21 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
22 error C2079: 'ClassTwo::m_ClassOne' uses undefined class 'ClassOne'
23 error C2146: syntax error : missing ';' before identifier 'message'
24 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
25 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
You cannot, ever, compile that code. You have described a system where type A contains type B, and type B contains type A. Therefore, both type A and B recursively and infinitely contain themselves, which is impossible. You must fundamentally re-architect your code to eliminate this problem.
Also, your friend syntax is wrong.
As said, you need to forward declare at least one of ClassOne or ClassTwo.
You ClassOne.h could therefor look like:
#ifndef _CLASS_ONE_
#define _CLASS_ONE_
#include <string>
class ClassTwo;
class ClassOne
{
private:
string message;
ClassTwo* m_ClassTwo;
public:
ClassOne();
void Display();
};
#endif
As you can see, we declare ClassTwo, but do not include it. We basically only tell the compiler that yes, we do have a ClassTwo, but we don't really care what it contains right now.
Also look at your ClassTwo member, this is now a pointer. The reason is that a member would require the compiler to know the size of the object, which we currently have no clue what is. Therefor you need either a pointer or a ref.
Next, in your ClassOne.cpp, would will need to include ClassTwo.h, to get the functions and size of that class.
A few things though:
With a forward declaration you can not inherit from ClassTwo, use the methods of the forwarded class in the header file (How would the compiler know which methods exists?) Define functions or methods using the forwarded class, that is you have to pass by reference or pass a pointer.
1) Use forward declarations:
add
class ClassTwo;
to ClassOne.h
and
class ClassTwo;
to ClassTwo.h
2) You need to create your member variables (or at least one of them) dynamically, using operator new, or if you wish, with one of the smart-pointers, like boost::shared_ptr from boost library or std::shared_ptr from standard library if you use C++11.

C++ Beginner - Trouble using classes inside of classes

I am working on a college project, where I have to implement a simple Scrabble game.
I have a player class (containing a Score and the player's hand, in the form of a std::string, and a score class (containing a name and numeric (int) score).
One of Player's member-functions is Score getScore(), which returns a Score object for that player. However, I get the following error on compile time:
player.h(27) : error C2146: syntax error : missing ';' before identifier 'getScore'
player.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
player.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
player.h(27) : warning C4183: 'getScore': missing return type; assumed to be a member function returning 'int'
player.h(35) : error C2146: syntax error : missing ';' before identifier '_score'
player.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
player.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Here's lines 27 and 35, respectively:
Score getScore(); //defined as public
(...)
Score _score; //defined as private
I get that the compiler is having trouble recognizing Score as a valid type... But why? I have correctly included Score.h at the beginning of player.h:
#include "Score.h"
#include "Deck.h"
#include <string>
I have a default constructor for Score defined in Score.h:
Score(); //score.h
//score.cpp
Score::Score()
{
_name = "";
_points = 0;
}
Any input would be appreciated!
Thanks for your time,
Francisco
EDIT:
As requested, score.h and player.h:
http://pastebin.com/3JzXP36i
http://pastebin.com/y7sGVZ4A
You've got a circular inclusion problem - relatively easy to fix in this case.
Remove the #include "Player.h" from Score.h.
See this question for an explanation and discussion of what you'd need to do if Score actually used Player.
As for the compiler errors you're getting, that's how Microsoft's compiler reports the use of undefined types -you should learn to mentally translate them all into "Type used in declaration not defined".
Your problem is the recursive include: Score.h is trying to include Player.h, and Player.h is trying to include Score.h. Since the Score class doesn't seem to actually be using the Player class, removing #include "Player.h" from Score.h should solve your problem.
You have a circular dependency problem : Score.h includes Player.h and Player.h includes Score.h.
Do solve this problem, delete your include to Player.h in Score.h and define class Player; if you need to use it in Score class.

Trouble compiling a header file in VC++

I just reorganized the code for a project and now I'm getting errors I can't resolve. This header is included by a .cpp file trying to compile.
#include "WinMain.h"
#include "numDefs.h"
#include <bitset>
class Entity
{
public:
Entity();
virtual ~Entity();
virtual bitset<MAX_SPRITE_PIXELS> getBitMask();
virtual void getMapSection(float x, float y, int w, int h, bitset<MAX_SPRITE_PIXELS>* section);
};
I'm getting these compiler errors for the declaration of Entity::getBitMask():
error C2143: syntax error : missing ';' before '<'
error C2433: 'Entity::bitset' : 'virtual' not permitted on data declarations
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
There are more similar errors for the next line as well. It seems like bitset isn't getting included but it clearly is? I can't figure out what's going wrong. WinMain.h includes windows.h, and numDefs.h includes nothing.
Using MS Visual C++ 2008.
Declare the bitset as std::bitset<MAX_SPRITE_PIXELS>.
The bitset template is defined in the std:: namespace, so you either need to reference it by it's full name std::bitset or add using namespace std; somewhere before the class declaration.
I think you need to say std::bitset.
Looks like an error in "numDefs.h"