extern

extern NSString *const in a class.

人走茶凉 提交于 2019-12-23 09:41:52
问题 Hi I've got this header file: #import <Foundation/Foundation.h> @interface PCConstants : NSObject extern NSString *const kPCUserProfileKey; extern NSString *const kPCUserProfileNameKey; extern NSString *const kPCUserProfileFirstNameKey; extern NSString *const kPCUserProfileLocationKey; extern NSString *const kPCUserProfileGenderKey; extern NSString *const kPCUserProfileBirthDayKey; extern NSString *const kPCUserProfileInterestedInKey; @end implementation: #import "PCConstants.h"

Why does this separate definition cause an error?

烈酒焚心 提交于 2019-12-23 07:56:10
问题 Challenge: I have this code that fails to compile. Can you figure out what's wrong? It caused headache to me once. // header namespace values { extern std::string address; extern int port; } // .cpp file std::string ::values::address = "192.0.0.1"; int ::values::port = 12; It looks correct on the first sight. How many and which are the errors!? 回答1: One error: std::string values::address = "192.0.0.1"; is the proper form, otherwise the parse is std::string::values::address = "192.0.0.1"; and

How does extern work?

倖福魔咒の 提交于 2019-12-22 09:18:56
问题 extern is a storage class in C. How exactly does it work? The output of the code given below is 20. How is this the output? #include <stdio.h> int main() { extern int a; printf("%d", a); return 0; } int a=20; 回答1: It means three things: The variable has external linkage , and is accessible from anywhere in the program; It has static storage duration , so its lifetime is that of the program (more or less); and The declaration is just a declaration, not a definition. The variable must also be

队列的图文解析 和 对应3种语言的实现(C/C++/Java)

一世执手 提交于 2019-12-22 05:31:57
概要 本章和介绍" 栈 "时的流程一样,先对队列进行介绍,然后分别给出队列的C、C++和Java三种语言的实现。内容包括: 1. 队列的介绍 2. 队列的C实现 3. 队列的C++实现 4. 队列的Java实现 转载请注明出处: http://www.cnblogs.com/skywang12345/p/3562279.html 更多内容: 数据结构与算法系列 目录 队列的介绍 队列(Queue),是一种线性存储结构。它有以下几个特点: (01) 队列中数据是按照"先进先出(FIFO, First-In-First-Out)"方式进出队列的。 (02) 队列只允许在"队首"进行删除操作,而在"队尾"进行插入操作。 队列通常包括的两种操作: 入队列 和 出队列 。 1. 队列的示意图 队列中有10,20,30共3个数据。 2. 出队列 出队列前 :队首是10,队尾是30。 出队列后 :出队列(队首)之后。队首是20,队尾是30。 3. 入队列 入队列前 :队首是20,队尾是30。 入队列后 :40入队列(队尾)之后。队首是20,队尾是40。 下面介绍队列的实现,分别介绍C/C++/Java三种实现 队列的C实现 共介绍4种C语言实现。 1. C语言实现一:数组实现的队列,并且只能存储int数据。 2. C语言实现二:单向链表实现的队列,并且只能存储int数据。 3. C语言实现三

栈的图文解析 和 对应3种语言的实现(C/C++/Java)

限于喜欢 提交于 2019-12-22 05:31:39
概要 本章会先对栈的原理进行介绍,然后分别通过C/C++/Java三种语言来演示栈的实现示例。注意:本文所说的栈是数据结构中的栈,而不是内存模型中栈。内容包括: 1. 栈的介绍 2. 栈的C实现 3. 栈的C++实现 4. 栈的Java实现 转载请注明出处: http://www.cnblogs.com/skywang12345/p/3562239.html 更多内容: 数据结构与算法系列 目录 栈的介绍 栈(stack),是一种线性存储结构,它有以下几个特点: (01) 栈中数据是按照"后进先出(LIFO, Last In First Out)"方式进出栈的。 (02) 向栈中添加/删除数据时,只能从栈顶进行操作。 栈通常包括的三种操作: push 、 peek 、 pop 。 push -- 向栈中添加元素。 peek -- 返回栈顶元素。 pop -- 返回并删除栈顶元素的操作。 1. 栈的示意图 栈中的数据依次是 30 --> 20 --> 10 2. 出栈 出栈前 :栈顶元素是30。此时,栈中的元素依次是 30 --> 20 --> 10 出栈后 :30出栈之后,栈顶元素变成20。此时,栈中的元素依次是 20 --> 10 3. 入栈 入栈前 :栈顶元素是20。此时,栈中的元素依次是 20 --> 10 入栈后 :40入栈之后,栈顶元素变成40。此时,栈中的元素依次是

extern "C" _declspec (dllexport)和_declspec (dllexport)的分别

早过忘川 提交于 2019-12-21 21:58:59
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> extern "C "只是表示这个可以被C语言调用,除了这个之外,没有什么更多含义。 因为C语言的编译器和C++的不同,C++的会有个叫做函数名打散的机制,比如函数:int add(int a,int b)在C++里面编译之后,就不是int add(int a,int b),而是类似:int add@WEROIUERH(int a,int b)的函数名,而且是随机的,如果不用extern "C ",C语言根本没法调用,而在C++里面可以通过@的顺序来调用。 __declspec (dllexport)输出函数的时候,用loadlibrary又有何不可? 关键是你要知道输出符号的名字。 因为c++中有函数重载,通过函数名并不能唯一确定一个函数,所以使用c++方式编译函数时系统会在目标码中的内部修饰符中加入参数信息和返回值信息等, 这时候你能估算出正确的名称吗? 如果加了extern "C "则是用c的方式编译,函数在目标码中的内部修饰符就是_函数名,只要用函数名就可以调用 由于C++里面有函数重载,所以在编译的时候,编译器会在你写的,也就是你希望导出的函数 后面加上一些关于参数的信息,也就是真正导出的函数名字和你想要的不一样。 又由于C语言没有函数重载,所以用EXTERN "C"的意思就是告诉编译器不要按照C+

C++ global extern “C” friend can't reach private member on namespaced class

自作多情 提交于 2019-12-21 09:23:14
问题 Please consider the code: #include <iostream> using namespace std; extern "C" void foo( void ); namespace A { template< int No > class Bar { private: friend void ::foo( void ); static void private_func( int n ); }; template< int No > void Bar< No >::private_func( int n ) { cout << "A:Bar< " << No << ">::private_func( " << n << " )" << endl; } } extern "C" void foo( void ) { A::Bar< 0 >::private_func( 1 ); } int main( ) { cout << " ---- " << endl; foo( ); } G++ gives: > g++ -Wall -o extern_c

c++库 c语言接口

岁酱吖の 提交于 2019-12-21 09:05:19
//code in add.cxx #include "add.h" int sample::method() { cout<<"method is called!\n"; } //code in add.h #include <iostream> using namespace std; class sample { public: int method(); }; 由于在C中不能识别类,所以要将上面类的成员函数,要封装成C接口函数才能被调用。下面进行封装,将输出接口转换成C接口。 //code in mylib.cxx #include "add.h" #ifndef _cplusplus #define _cplusplus #include "mylib.h" #endif int myfunc() { sample ss; ss.method(); return 0; } //code in mylib.h #ifdef _cplusplus extern "C" { #endif int myfunc(); #ifdef _cplusplus } #endif 在linux下,gcc编译器并没用变量_cplusplus来区分是C代码还是C++ 代码(没有宏定义),如果使用gcc编译器,这里我们可以自己定义一个变量_cplusplus用于区分C和C++代码

Changing the value of an external variable

天涯浪子 提交于 2019-12-21 05:42:10
问题 We have in File1.c int arr[10]; And in File2.c extern int *arr; int main() { arr[0]=10; return 0; } What are the problems that can occur with this and why? 回答1: An array isn't a pointer. The memory access will be wrong. In File1.c , you have the memory layout: +---+---+---+---+---+---+---+---+---+---+ + 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | +---+---+---+---+---+---+---+---+---+---+ ^ arr In File2.c , you've told the compiler you have the memory layout: +-------+ | ptr | +-------+ ^ arr

extern enum in c++

心不动则不痛 提交于 2019-12-21 04:22:18
问题 I have an enum I have declared in some .h file: typedef enum { NONE, ONE, TWO, THREE } MYENUM; in a seperate .cpp I cannot do this: extern enum MYENUM; //works extern MYENUM TWO; //makes sence, TWO is not an INSTANCE of MYENUM... how would one do so without including the whole header where the enum is declared? 回答1: You can't use an incomplete type. You can only pass around pointers to it. This is because until the type is completed, the compiler doesn't know how big it is. OTOH a pointer is