Re: [問題] extern "C"的問題
不好意思 我現在自己想問題測試 其實我對extern "C"真的不是很懂
z大說的我明白
而我現在寫法是這樣如下
main.cpp
#include <iostream>
using namespace std;
#include "test.h"
int main()
{
foo2();
system("PAUSE");
return 0;
}
test.c
#include <stdlib.h>
#include <stdio.h>
typedef struct FF{
int a;
int b;
}FU;
void foo(){
printf("@@");
}
FU* foo2()
{
FU* p=(FU*)malloc(sizeof(FU));
printf("FU");
return p;
}
test.h
#ifndef _TEST_H
#define _TEST_H
#include <stdlib.h>
#include <stdio.h>
extern "C"
{
struct FU;
void foo();
FU* foo2();
}
#endif
以上這樣寫 是為了讓 test.c不去include test.h(我那個struct .c必須用到)
這樣可以compile過 但是我繼續想辦法try
我將extern "C"拿掉 test.c改成test.cpp
竟然就認不到了...........
原因很想請板上高手解釋一下
因為我知道struct改成class的話 上面的改法 就不會有問題
1.為什麼struct卻不能呢?
2.一開始我這樣故意把.c的include .h拿掉是不是一個好的作法?
不然勢必extern "C"就要寫在main ==>extern "C"{include "test.h"}
很抱歉問題有點多
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.207.187
推
06/10 13:48, , 1F
06/10 13:48, 1F
推
06/10 13:50, , 2F
06/10 13:50, 2F
→
06/10 13:50, , 3F
06/10 13:50, 3F
→
06/10 13:50, , 4F
06/10 13:50, 4F
→
06/10 13:51, , 5F
06/10 13:51, 5F
推
06/10 13:51, , 6F
06/10 13:51, 6F
→
06/10 13:52, , 7F
06/10 13:52, 7F
→
06/10 13:52, , 8F
06/10 13:52, 8F
→
06/10 14:04, , 9F
06/10 14:04, 9F
→
06/10 14:05, , 10F
06/10 14:05, 10F
→
06/10 14:05, , 11F
06/10 14:05, 11F
推
06/10 14:16, , 12F
06/10 14:16, 12F
推
06/10 14:23, , 13F
06/10 14:23, 13F
→
06/10 14:24, , 14F
06/10 14:24, 14F
→
06/10 14:26, , 15F
06/10 14:26, 15F
→
06/10 14:40, , 16F
06/10 14:40, 16F
→
06/10 14:41, , 17F
06/10 14:41, 17F
推
06/10 14:51, , 18F
06/10 14:51, 18F
→
06/10 14:51, , 19F
06/10 14:51, 19F
→
06/10 14:51, , 20F
06/10 14:51, 20F
→
06/10 14:52, , 21F
06/10 14:52, 21F
→
06/10 14:55, , 22F
06/10 14:55, 22F
→
06/10 14:56, , 23F
06/10 14:56, 23F
推
06/10 14:59, , 24F
06/10 14:59, 24F
推
06/10 15:01, , 25F
06/10 15:01, 25F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章