静态外部? [英] static extern?

查看:52
本文介绍了静态外部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:


A.cpp:

------

静态FOO * gFoo = NULL;




extern FOO * gFoo;


给出:L2001 - 未解析的外部:" symbol struct FOO * gFoo"


如果Ah看起来像:

extern static FOO * gFoo;


它给出:

C2159:指定了多个存储类。


< blink,blink>

我现在该怎么做?我有一个prefedined宏,它会产生一个

静态FOO *。我想告诉我所有其他的.cpp文件,它们是stdafx.h中存在的



谢谢你,

-

-Gernot

int main(int argc,char ** argv){printf

("%silto%c%cf %cgl%ssic%ccom%c"," ma",58,''g'',64," ba",46,10);}


________________________________________

想找个好游戏吗?亲自动手吧!

GLBasic - 你可以这样做
www.GLBasic .com

Problem:

A.cpp:
------
static FOO* gFoo=NULL;

A.h
extern FOO* gFoo;

gives: L2001 - unresolved external: "symbol struct FOO* gFoo"

if A.h looks like:
extern static FOO* gFoo;

it gives:
C2159: more than one storage class specified.

<blink, blink>
How would I do this now? I have a prefedined macro that makes a
"static FOO*". And I want to tell all my other .cpp files that it
exists in stdafx.h.

Thank you,
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, ''g'', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com

推荐答案

试试这个:




静态FOO * gFoo;


A.cpp:

extern静态FOO * gFoo = NULL;


文斯


" Gernot Frisch" < Me@Privacy.net>在消息中写道

新闻:2k ************* @ uni-berlin.de ...
Try this:

A.h
static FOO* gFoo;

A.cpp:
extern static FOO* gFoo=NULL;

Vince

"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2k*************@uni-berlin.de...
问题:

A.cpp:
------
静态FOO * gFoo = NULL;

啊外出FOO * gFoo;

给出:L2001 - 未解析的外部:符号结构FOO * gFoo

如果啊看起来像:
extern static FOO * gFoo;
它给出了:
C2159:指定了多个存储类。

< blink,blink>
我现在该怎么做?我有一个prefedined宏,它会产生一个
静态FOO *。我想告诉我在stdafx.h中存在的所有其他.cpp文件。

谢谢你,

-
-Gernot
int main(int argc,char ** argv){printf
("%silto%c%cf%cgl%ssic%ccom%c"," ma",58,''g '',64," ba",46,10);}

________________________________________
寻找好游戏?亲自动手吧!
GLBasic - 你可以做
www.GLBasic.com
Problem:

A.cpp:
------
static FOO* gFoo=NULL;

A.h
extern FOO* gFoo;

gives: L2001 - unresolved external: "symbol struct FOO* gFoo"

if A.h looks like:
extern static FOO* gFoo;

it gives:
C2159: more than one storage class specified.

<blink, blink>
How would I do this now? I have a prefedined macro that makes a
"static FOO*". And I want to tell all my other .cpp files that it
exists in stdafx.h.

Thank you,
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, ''g'', 64, "ba", 46, 10);}

________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com



Gernot Frisch写道:
Gernot Frisch wrote:
问题:

A.cpp :
------
静态FOO * gFoo = NULL;

外出FOO * gFoo;

给出: L2001 - 未解析的外部:符号结构FOO * gFoo

如果啊看起来像:
extern static FOO * gFoo;

它给出:
C2159:指定了多个存储类。


是的,变量gFoo不能同时是静态的和外部的。

< blink,blink>
我该怎么做现在?我有一个prefedined宏,它会产生一个
静态FOO *。我想告诉我在stdafx.h中存在的所有其他.cpp文件。

谢谢,
Problem:

A.cpp:
------
static FOO* gFoo=NULL;

A.h
extern FOO* gFoo;

gives: L2001 - unresolved external: "symbol struct FOO* gFoo"

if A.h looks like:
extern static FOO* gFoo;

it gives:
C2159: more than one storage class specified.
Yes, the variable gFoo cannot be static and extern at the same time.
<blink, blink>
How would I do this now? I have a prefedined macro that makes a
"static FOO*". And I want to tell all my other .cpp files that it
exists in stdafx.h.

Thank you,




解决方案:


A.cpp:

------

FOO * gFoo = NULL; //注意没有静态




----

extern FOO * gFoo;

HTH


Mark



Solution:

A.cpp:
------
FOO* gFoo=NULL; // Note no static

A.h
----
extern FOO* gFoo;
HTH

Mark


>解决方案:

A.cpp:
------
FOO * gFoo = NULL; //注意没有静态

----
extern FOO * gFoo;

A.cpp:
------
FOO* gFoo=NULL; // Note no static

A.h
----
extern FOO* gFoo;




我重写了代码,所以我现在可以这样做。但我不明白。

为什么我不能告诉另一个.cpp文件,其他地方有静态变量



-Gernot



I rewrote the code so I can do this now. But I don''t understand it.
Why can''t I tell another .cpp file that there is an static variable
somewhere else?
-Gernot


这篇关于静态外部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆