Error: Declaration Does Not Declare Anything

Error: declaration does not declare anything

The problem is this code:

// header
#ifndef SymbolTable
#define SymbolTable

// implementation
map<std::string, Symbol> SymbolTable;

You #define SymbolTable to empty. Therefore the advise to

  1. Always use ALL_UPPERCASE_NAMES for macros (also for include guards)

  2. Use macro names only for macros.

declaration does not declare anything : warning?

The reason why the compiler is showing the warning is because it doesn't see a name for the variable of type address you defined for the emp struct, even though you do declare something using address on the next line, but I guess the compiler is not smart enough to figure that out.

As you showed, this produces a warning:

struct emp {
struct address {}; // This statement doesn't declare any variable for the emp struct.
struct address a1;
};

But not this:

struct emp {
struct address {} a1; // This statement defines the address struct and the a1 variable.
};

Or this:

struct address {};

struct emp {
struct address a1; //the only statement declare a variable of type struct address
};

The struct emp {} doesn't show any warnings since this statement is not inside a struct defintion block. If you did put it inside one of those then the compiler will show a warning for that as well. The following will show two warnings:

struct emp {
struct phone {};
struct name {};
};

declaration does not declare anything [-fpermissive] error

Replace near and far with something else, at least for a test, e.g. near_ and far_: I suspect you are compiling with some funny header which defines near and far to be nothing. In the distant past these two were keywords used on some platforms to deal with pointers of different sizes.

If you want to verify the theory, process the source file with the -E option (you may need to remove other options from the compile line, e.g., -c): with this option the compiler produces the preprocessed output. If you capture that and look at your class there I'm quite certain that it won't contain the member names.

Declaration does not declare anything error for #define

There are no semicolons after preprocessor directives.

So this:

#define ll long long int;

means ll is literally long long int;.

Then your declaration:

ll t;

is really:

long long int; t;

Which is the same as:

long long int;
t;

Hopefully now you can see why your compiler hates it.


As an aside, I realise you're doing "competitive programming [sic]" and that it is hip in that field to make everything short and unreadable, but macros like these are really to be avoided if you want to write anything approaching decent code. Similarly, do not include implementation headers.

gcc warning does not declare anything

Does the fault lie in the compiler?

This is a compiler bug. It appears to have been reported already: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66159 . The problem reproduces when an elaborated name specifier is used in a using declaration. In this case, you need to use elaborated name specifier to avoid ambiguity with the member that has the same name.

Workaround: Use typedef declaration instead:

typedef enum sample::what demo;

What is the reason for declaration does not declare anything error?

Rock is just the name of the class. There is no variable name declared. To call a constructor/create an object, you need to declare the name of a variable: Rock r;

This creates an object on the stack that will get destroyed when it goes out of scope

error: declaration does not declare anything [-Werror]|

You are probably using C compiler, but the code is C++ (that too C++14). You need to change the compiler (or toolset), or change the code so that it compiles with C compiler.

EDIT: Which line? Does it say struct Prestige is not utilized?

Based on your edit:

 typedef struct Prestige
{
u32 offset = 0x000000;
char data[13] = { 0x00, 0x01, 0x02, 0x03, 0x04,
0x05, 0x06, 0x07, 0x08, 0x09,
0x0A, 0x0B, 0x0C
};
} prestige; // Small letters
...
BO2Offsets BO2;
BO2.prestige.offset;

I've used small letters for the variable, so that it is clearly different from the type Prestige.

Error: declaration does not declare

register is a C++ keyword, you thus cannot use it as a variable name.

class Game{
static ItemRegister register;
^^^^^^^^

You can find a complete list of C++ keywords here.



Related Topics



Leave a reply



Submit