jinglei
jinglei

Reputation: 3363

c++ - error C3646: unknown override specifier

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?

Upvotes: 7

Views: 24438

Answers (3)

Meung Kim
Meung Kim

Reputation: 11

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__).

Upvotes: 1

TonyK
TonyK

Reputation: 17124

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

Upvotes: 20

doraemon
doraemon

Reputation: 2522

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"

Upvotes: 1

Related Questions