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

akunone akunone 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题:


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;
}

...全文
评论 9
收藏 已收藏
分享
返回顶部
akunone
C++ 语言 65,214 成员 250,514 内容