错误:声明不声明任何内容 [英] Error: declaration does not declare anything
问题描述
这是一个非常业余的问题,我确信这将是一个非常简单的答案,但我似乎无法弄清楚问题所在。我有一个头文件与一个相应的.cpp文件,但由于某种原因,每当我尝试用g ++编译,我不断收到错误:
声明不会声明任何东西
我很确定问题在于我没有初始化(仅)变量该文件,但我不确定要初始化它。如果有人能帮忙,我会非常感激!以下是我的文件:
SymbolTableDictionary.h
#ifndef SymbolTable
#define SymbolTable
#include< new>
#include< iostream>
#include< stdio.h>
#include< stdlib.h>
#include< string>
使用namespace std;
#pragma一次
结构符号
{
std :: string名称;
int地址;
符号::符号()
{}
符号::符号(常量字符串名称,int地址)
{
std :: string sym(name);
this-> Name = sym;
this-> Address = address;
}
};
extern map< std :: string,Symbol>符号表;
#endif
SymbolTableDictionary.cpp
#include< new>
#include< iostream>
#include< stdio.h>
#include< stdlib.h>
#include< string>
#include< map>
#includeSymbolTableDictionary.h
using namespace std;
map< std :: string,Symbol>符号表;
编译错误:
在SymbolTableDictionary.cpp包含的文件中:8:0:
SymbolTableDictionary.h:18:5:error:成员'Symbol'上额外限定'Symbol ::'[-fpermissive]
SymbolTableDictionary.h:21:5:错误:额外的资格 '符号::' 会员 '符号'[-fpermissive]
SymbolTableDictionary.h:29:8:错误:声明没有宣布任何东西[-fpermissive ]
SymbolTableDictionary.cpp:12:1:错误:声明不声明任何东西[-fpermissive]
问题是这样的代码:
// header
#ifndef SymbolTable
#define SymbolTable
//执行
map< std :: string,Symbol>符号表;
您将#define SymbolTable
清空。因此,建议
-
总是对宏使用ALL_UPPERCASE_NAMES(也用于包含防护)
-
仅针对宏使用宏名称。
This is a very amateur question with what I'm sure is going to be a very simple answer, but I cannot seem to figure out the problem. I have a header file with a corresponding .cpp file, but for some reason whenever I try to compile with g++, I keep getting the error:
declaration does not declare anything
I'm pretty sure the problem is that I'm not initializing the (only) variable in the file, but I'm not sure what to initialize it to. If anyone can help, I would greatly appreciate it! Here are my files:
SymbolTableDictionary.h
#ifndef SymbolTable
#define SymbolTable
#include <new>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
#pragma once
struct Symbol
{
std::string Name;
int Address;
Symbol::Symbol()
{ }
Symbol::Symbol(const string name, int address)
{
std::string sym(name);
this->Name = sym;
this->Address = address;
}
};
extern map<std::string, Symbol> SymbolTable;
#endif
SymbolTableDictionary.cpp
#include <new>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <map>
#include "SymbolTableDictionary.h"
using namespace std;
map<std::string, Symbol> SymbolTable;
Compilation errors:
In file included from SymbolTableDictionary.cpp:8:0:
SymbolTableDictionary.h:18:5: error: extra qualification ‘Symbol::’ on member ‘Symbol’ [-fpermissive]
SymbolTableDictionary.h:21:5: error: extra qualification ‘Symbol::’ on member ‘Symbol’ [-fpermissive]
SymbolTableDictionary.h:29:8: error: declaration does not declare anything [-fpermissive]
SymbolTableDictionary.cpp:12:1: error: declaration does not declare anything [-fpermissive]
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
Always use ALL_UPPERCASE_NAMES for macros (also for include guards)
Use macro names only for macros.
这篇关于错误:声明不声明任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!