这是一个非常业余的问题,我敢肯定这将是一个非常简单的答案,但我似乎无法弄清楚问题所在。我有一个带有相应 .cpp 文件的头文件,但由于某种原因,每当我尝试使用 g++ 进行编译时,我都会不断收到错误消息:
声明没有声明任何东西
我很确定问题是我没有初始化文件中的(唯一)变量,但我不确定将它初始化为什么。如果有人可以提供帮助,我将不胜感激!这是我的文件:
符号表字典.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
符号表字典.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;
编译错误:
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]