C++ 致命错误LNK1120:c+中有1个未解析的外部+;
我用c++编写了一段代码:C++ 致命错误LNK1120:c+中有1个未解析的外部+;,c++,visual-studio-2005,set,linker-errors,C++,Visual Studio 2005,Set,Linker Errors,我用c++编写了一段代码: #include<iostream> #include<string> #include<map> #include<set> #include<list> #include<vector> #include<fstream> using namespace std; #ifndef u32 typedef unsigned int u32; #endif vector<s
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<fstream>
using namespace std;
#ifndef u32
typedef unsigned int u32;
#endif
vector<string> get_NodeProps(){
vector<string> NodeProps;
NodeProps.push_back("ObjType");
NodeProps.push_back("Nexus");
return NodeProps;
};
vector<string> NodeProps = get_NodeProps();
map<u32,string> create_OMSSObj_map(){
map<u32,string> OMSSObjTypeByID1;
OMSSObjTypeByID1.insert(pair<u32,string>(768,"storage"));
OMSSObjTypeByID1.insert(pair<u32,string>(769,"adapter"));
return OMSSObjTypeByID1;
};
map<u32,string> getOMSSObjTypeByID = create_OMSSObj_map();
template<typename TKey,typename TValue>
class Node{
map<TKey,TValue> objProperties;
public:
Node();
Node(const map<TKey,TValue>& m);
bool operator<(Node const& a2 ) const{
Node const& a1 = *this;
map<TKey,TValue>::iterator it1=a1.objProperties.begin();
map<TKey,TValue>::iterator it2=a2.objProperties.begin();
while(it1!=a1.objProperties.end() && it2!=a2.objProperties.end()){
if((*it1).second < (*it2).second)
return true;
else if((*it1).second > (*it2).second)
return false;
it1++;
it2++;
}
};
map<TKey,TValue> getObjProperties();
TValue getObjPropertyValue(TKey Key);
void setObjProperty(TKey key,TValue Value);/*Change Value of Key if Key is available, add new key-value pair otherwise*/
u32 removeProperty(TKey Key);
};
template<typename TKey,typename TValue>
Node<TKey,TValue>::Node(const map<TKey,TValue>& m){
objProperties = m;
};
template<typename TKey,typename TValue>
map<TKey,TValue> Node<TKey,TValue>::getObjProperties(){
return objProperties;
};
template<typename TKey,typename TValue>
TValue Node<TKey,TValue>::getObjPropertyValue(TKey Key){
/*if(objProperties.count(Key)>0)
return objProperties[Key];
else
return TValue();*/
return objProperties[Key];//This work same as above(if-else)?
};
template<typename TKey,typename TValue>
void Node<TKey,TValue>::setObjProperty(TKey Key,TValue Value){
if(!objProperties.insert(pair<TKey,TValue>(Key,Value)).second){//Key already exist: so change the Value of corresponding Key
objProperties[Key] = Value;
}
};
template<typename TKey,typename TValue>
u32 Node<TKey,TValue>::removeProperty(TKey Key){
return objProperties.erase(Key);//returns 1 if erased & 0 if Key not available
};
template<typename TKey,typename TValue>
class OMSSStorage{
set<Node<TKey,TValue>> StorageTree;
public:
u32 addNode(Node<TKey,TValue>);
u32 deleteNode(Node<TKey,TValue>);
u32 contains(Node<TKey,TValue>);
set<Node<TKey,TValue>> getStorageTree();
u32 size();
};
template<typename TKey,typename TValue>
u32 OMSSStorage<TKey,TValue>::addNode(Node<TKey,TValue> n){
return StorageTree.insert(n).second;
};
template<typename TKey,typename TValue>
u32 OMSSStorage<TKey,TValue>::deleteNode(Node<TKey,TValue> n){
return StorageTree.erase(n);
};
template<typename TKey,typename TValue>
u32 OMSSStorage<TKey,TValue>::contains(Node<TKey,TValue> n){
return(StorageTree.find(n) != StorageTree.end());
};
template<typename TKey,typename TValue>
set<Node<TKey,TValue>> OMSSStorage<TKey,TValue>::getStorageTree(){
return(StorageTree);
};
template<typename TKey,typename TValue>
u32 OMSSStorage<TKey,TValue>::size(){
return StorageTree.size();
};
template<typename TKey,typename TValue>
void addDCStorageObject(OMSSStorage<TKey,TValue>,string,int);
string getValueByName(string str,string name);
template<typename TKey,typename TValue>
void addDCStorageObject(OMSSStorage<TKey,TValue> tree,string StorObj,int propcount=2){
if((int)NodeProps.size() < propcount)
return;
Node<string,string> n;
for(int i=0; i<propcount ; i++){
n.setObjProperty(NodeProps[i],getValueByName(StorObj,NodeProps[i]));
}
return;
};
string getValueByName(string obj,string name){
int start,end;
string value,temp="<",temp1="</";
temp.append(name);
temp1.append(name);
start=(int)obj.find(temp);
end=(int)obj.find(temp1);
value=obj.substr(start,end-start);
value=value.substr(value.find(">")+1,end-start);
return value;
}
int main(){
OMSSStorage<string,string> StObj;
ifstream ifs("C:\\Users\\Public\\Documents\\share\\STORAGE.txt",ifstream::in);
string line;
string obj="";
int start=0,end=0;
while (ifs.good()){
getline(ifs,line);
if((line.find("<DCStorageObject>",0)) != string::npos && start==0){
obj.clear();
start=1;
end=0;
obj.append(line);
obj.append("\n");
}
else if((line.find("</DCStorageObject>",0)) != string::npos && end==0){
start=0;
end=1;
obj.append(line);
}
else{
obj.append(line);
obj.append("\n");
}
if(end==1){
addDCStorageObject(StObj,obj,2);
}
}
set<Node<string,string>> o = StObj.getStorageTree();
set<Node<string,string>>::iterator its=o.begin();
while(its!=o.end()){
cout<<"<StorageObj>:\n";
map<string,string> m=(*its).getObjProperties();
map<string,string>::iterator itm=m.begin();
while(itm!=m.end()){
cout<<(*itm).first<<" => "<<(*itm).second<<endl;
}
}
ifs.close();
cin.get();
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
#ifndef u32
typedef无符号整数u32;
#恩迪夫
向量get_NodeProps(){
向量节点操作;
NodeProps.push_back(“对象类型”);
NodeProps.push_back(“Nexus”);
返回节点操作;
};
向量NodeProps=get_NodeProps();
地图创建_OMSSObj_地图(){
映射OMSSObjTypeByID1;
OMSSObjTypeByID1.插入(成对(768,“存储”);
OMSSObjTypeByID1.插入(成对(769,“适配器”);
返回OMSSObjTypeByID1;
};
map getOMSSObjTypeByID=create_OMSSObj_map();
模板
类节点{
地图对象属性;
公众:
Node();
节点(const-map&m);
布尔运算符(*it2)。秒)
返回false;
it1++;
it2++;
}
};
映射getObjProperties();
TValue getObjPropertyValue(TKey);
void setObjProperty(TKey键、TValue值)/*如果密钥可用,则更改密钥的值,否则添加新的密钥-值对*/
u32 removeProperty(TKey);
};
模板
节点::节点(常量映射和m){
OBJProperty=m;
};
模板
映射节点::getObjProperties(){
归还不动产;
};
模板
TValue节点::getObjPropertyValue(TKey){
/*if(objproperty.count(键)>0)
返回对象属性[键];
其他的
返回TValue()*/
返回objproperty[Key];//此工作与上面相同(如果其他)?
};
模板
void节点::setObjProperty(TKey键,TValue值){
如果(!objproperty.insert(pair(Key,Value)).second){//Key已经存在:那么更改相应Key的值
OBJProperty[键]=值;
}
};
模板
u32节点::removeProperty(TKey){
return objproperty.erase(Key);//如果已擦除,则返回1;如果键不可用,则返回0
};
模板
类OMSSStorage{
设置存储树;
公众:
u32 addNode(Node);
u32删除节点(Node);
u32包含(节点);
设置getStorageTree();
u32大小();
};
模板
u32 OMSSStorage::addNode(节点n){
返回StorageTree.insert(n).second;
};
模板
u32 OMSSStorage::deleteNode(节点n){
返回StorageTree.erase(n);
};
模板
u32 OMSSStorage::包含(节点n){
return(StorageTree.find(n)!=StorageTree.end());
};
模板
设置OMSSStorage::getStorageTree(){
返回(StorageTree);
};
模板
u32 OMSSStorage::size(){
返回StorageTree.size();
};
模板
void addDCStorageObject(OMSSStorage,string,int);
字符串getValueByName(字符串str,字符串名称);
模板
void addDCStorageObject(OMSSStorage树,字符串StorObj,int-propcount=2){
if((int)NodeProps.size() 对于(inti=0;i,您只需仔细阅读错误消息即可找到缺失函数的名称(很痛苦,但肯定是可能的)
在本例中,它表示没有定义节点::节点();
——您声明了它,但从未定义过它
编辑:我应该补充一点,我几乎没有回答这个问题——这是一个几乎完美的例子,需要将问题缩减到演示问题的最小代码段(在这一点上,您可能不必再发布更多,因为问题可能已经很明显了).您只需仔细阅读错误消息即可找到缺少的函数的名称(很痛苦,但肯定是可能的)
在本例中,它表示没有定义节点::节点();
——您声明了它,但从未定义过它
编辑:我应该补充一点,我几乎没有回答这个问题——这是一个几乎完美的例子,需要将问题缩减到演示问题的最小代码段(在这一点上,您可能不必再发布更多,因为问题可能已经很明显了).我无法读取错误消息。请在新选项卡/窗口中打开图像。我无法读取错误消息。请在新选项卡/窗口中打开图像。。