相关疑难解决方法(0)

C中的命名空间

有没有办法(ab)使用C预处理器来模拟C中的命名空间?

我正在考虑以下几点:

#define NAMESPACE name_of_ns
some_function() {
    some_other_function();
}
Run Code Online (Sandbox Code Playgroud)

这将被翻译为:

name_of_ns_some_function() {
    name_of_ns_some_other_function();
}
Run Code Online (Sandbox Code Playgroud)

c c++ namespaces c-preprocessor

51
推荐指数
6
解决办法
5万
查看次数

从C文件调用C++函数

我是C和C++的新手.但我有一些C++函数,我需要从C调用它们.我做了一个我需要做的例子


main.c:

#include "example.h"      
#include <stdio.h>

int main(){   
    helloWorld();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

example.h:

 #ifndef HEADER_FILE
 #define HEADER_FILE

 #ifdef __cplusplus
     extern "C" {
 #endif
         void helloWorld();
 #ifdef __cplusplus
     }
 #endif

 #endif
Run Code Online (Sandbox Code Playgroud)

example.cpp:

#include <iostream.h>

void helloWorld(){
    printf("hello from CPP");
} 
Run Code Online (Sandbox Code Playgroud)

它只是不起作用.我仍然收到未定义参考错误_helloWorld在我main.c.这个问题在哪里?

c c++ merge call

11
推荐指数
1
解决办法
2万
查看次数

为什么我会收到命名空间标识符错误?

我正在使用 Keil uVision 并且不断收到此错误:

C:\Keil_v5\ARM\ARMCC\bin\..\include\rw/_defs.h(781): error:  #20:
    identifier "namespace" is undefined
Run Code Online (Sandbox Code Playgroud)

什么可能导致此错误?命名空间不是自动定义的吗?

c++ embedded namespaces keil rogue-wave

5
推荐指数
1
解决办法
7471
查看次数

标签 统计

c++ ×3

c ×2

namespaces ×2

c-preprocessor ×1

call ×1

embedded ×1

keil ×1

merge ×1

rogue-wave ×1