c++ 头文件里申明的函数部分无法被调用 跪求助攻
问题:

list.h 函数申明 ( list.cpp里函数定义) (listsort.cpp 程序入口) (文件都在一个工程下) 最后两个函数无法调用
list.cpp 函数定义 最后两个函数无法在listsort.cpp里调用
listsort.cpp 程序入口

list.h 函数申明 ( list.cpp里函数定义) (listsort.cpp 程序入口) (文件都在一个工程下) 最后两个函数无法调用
struct ListNode
{
int m_nValue;
ListNode* m_pNext;
};
_declspec(dllexport) ListNode* CreateListNode(int value);
_declspec(dllexport) void ConnectListNodes(ListNode* pCurrent, ListNode* pNext);
_declspec(dllexport) void PrintListNode(ListNode* pNode);
_declspec(dllexport) void PrintList(ListNode* pHead);
_declspec(dllexport) void DestroyList(ListNode* pHead);
_declspec(dllexport) void AddToTail(ListNode** pHead, int value);
_declspec(dllexport) void RemoveNode(ListNode** pHead, int value);
_declspec(dllexport) void PrintListReverse(ListNode* pHead); //无法调用
_declspec(dllexport) void PrintListReverse_Recursion(ListNode* pHead); //无法调用
list.cpp 函数定义 最后两个函数无法在listsort.cpp里调用
#include "stdafx.h"
#include "list.h"
#include "stdio.h"
#include "stdlib.h"
#include<stack>
#include<iostream.h>
ListNode* CreateListNode(int value)
{
ListNode* pNode = new ListNode();
pNode->m_nValue = value;
pNode->m_pNext = NULL;
return pNode;
}
void ConnectListNodes(ListNode* pCurrent, ListNode* pNext)
{
if(pCurrent == NULL)
{
printf("ERROR to connect nodes.\n");
exit(1);
}
pCurrent->m_pNext = pNext;
}
void PrintListNode(ListNode* pNode)
{
if(pNode == NULL)
{
printf("pNode is NULL.\n");
}
else
{
printf("pNode is %d.\n", pNode->m_nValue);
}
}
void PrintList(ListNode* pHead)
{
ListNode* pNode = pHead;
while(pNode != NULL)
{
printf(" %d.\t", pNode->m_nValue);
pNode = pNode->m_pNext ;
}
printf("\n");
}
void DestroyList(ListNode* pHead)
{
ListNode* pNode = pHead;
while(pNode != NULL)
{
delete pNode;
pHead = pHead->m_pNext;
pNode = pHead ;
}
}
void AddToTail(ListNode** pHead, int value)
{
ListNode* pNew = new ListNode();
pNew->m_nValue = value;
pNew->m_pNext = NULL;
if(*pHead == NULL)
{
*pHead = pNew;
}
else
{
ListNode* pNode = *pHead;
while(pNode->m_pNext != NULL)
{
pNode = pNode->m_pNext;
}
pNode->m_pNext = pNew;
}
}
void RemoveNode(ListNode** pHead, int value)
{
if(pHead==NULL || *pHead==NULL)
{
return;
}
ListNode* pToBeDelete = NULL;
if((*pHead)->m_nValue == value)
{
pToBeDelete = *pHead;
*pHead = (*pHead)->m_pNext ;
}
else
{
ListNode* pNode = *pHead;
while(pNode->m_pNext != NULL && (pNode)->m_pNext->m_nValue != value)
{
pNode = pNode->m_pNext;
}
if(pNode->m_pNext != NULL && (pNode)->m_pNext->m_nValue == value)
{
pToBeDelete = pNode->m_pNext;
pNode->m_pNext = pNode->m_pNext->m_pNext ;
}
}
if(pToBeDelete != NULL)
{
delete pToBeDelete;
pToBeDelete = NULL;
}
}
////////////////////////////无法调用///////////////////////////////////////////////
void PrintListReverse(ListNode* pHead)
{
std::stack<ListNode*> nodes;
ListNode* pNode = pHead;
while(pNode != NULL)
{
nodes.push(pNode);
pNode = pNode->m_pNext ;
}
while(!nodes.empty())
{
pNode = nodes.top();
printf("%d \t", pNode->m_nValue);
nodes.pop();
}
printf(" \n");
}
void PrintListReverse_Recursion(ListNode* pHead)
{
if(pHead != NULL)
{
if(pHead->m_pNext != NULL)
PrintListReverse_Recursion(pHead->m_pNext);
printf("%d \t", pHead->m_nValue);
}
}
//////////////////////////////无法调用/////////////////////////////////////////////////
listsort.cpp 程序入口
#include "stdafx.h"
#include "stdlib.h"
#include "list.h"
#include<iostream.h>
#include<stack>
using namespace std;
//void PrintListReverse(ListNode* pHead);
//void PrintListReverse_Recursion(ListNode* pHead); //需在此申明 否则无法识别
void printlist_re()
{
ListNode* node1 = CreateListNode(1);
ListNode** p_node1 = &node1;
AddToTail(p_node1, 2);
AddToTail(p_node1, 3);
AddToTail(p_node1, 4);
AddToTail(p_node1, 5);
PrintList(*p_node1);
PrintListReverse(node1); //错误 1 error C3861: “PrintListReverse”: 找不到标识符
PrintListReverse_Recursion(node1); //错误 2 error C3861: “PrintListReverse_Recursion”: 找不到标识符
}
int _tmain(int argc, _TCHAR* argv[])
{
printlist_re();
system("pause");
return 0;
}
...全文
相关推荐
C++ .h和.cpp文件总结
总结了.h文件能做什么,.cpp文件能做什么,总结了.h文件的本质,方便新手在遇到文件包含、类型声明、变量定义时能理清.h与.cpp关系,纯属个人总结文档。
C、C++常用头文件及函数汇总
列举了C/C++常用头文件及函数,保存下来可以供随时查阅
C++常用函数所在头文件一览表
里面有一些常用C++函数所在的头文件,方便大家查找
C生成静态库给C++调用出现undefined reference to ...解决方案_cpp
C生成静态库给C++调用出现undefined reference to ...解决方案 已经写好makefile,还有头文件,看注释,基本没问题的
C++的头文件和实现文件分别写什么
C++的头文件和实现文件分别写什么


