Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Cant extern a vector if its declared in a header?

Author
Message
Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jul 2006 03:10
Just a general c++ question, im sure somebody here can answer.

Why is it that if you declare a vector in one cpp



Then 'tell' another cpp about it via the extern command



Everything works fine. This works for any data type (ints, floats, even custom data structs). HOWEVER! For some krazy ass reason this ONLY works IF the vector is declared in a cpp. If you declare the vector in a header, and include that header in the main cpp you get the following error...



The krazy part is, this is ONLY a problem with vectors. EVERY other data type can be externed just fine, if its declared in a cpp, header, doesnt matter. Why?!

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jul 2006 03:15
it's header order. Your trying to use the vector template before #include <vector> is used possibly?

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jul 2006 03:21
I dont see how it can be the order... The vector is declared during the app 'initialization'. The vector isnt actually 'used' until later in the main loop.

All you need is zeal
Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 27th Jul 2006 03:29
remember, headers are not compiled, they get added to cpp files which are compiled into objects and if that object does not have a link to the relevent lib that you tried to use in the header them boom.

secondly however, why would you want to declare a variable in a header?! typedefs, yes. prototypes yes, externs yes, static/constants yes - but actual generic variables in a header file? sounds like its asking for trouble to me

Zeal
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jul 2006 03:36
Whoops nm! Was a error on my end, looks like it DOES work from a header.

As for WHY I want to declare variables inside a header... heh its a long story.

All you need is zeal

Login to post a reply

Server time is: 2024-11-19 06:28:36
Your offset time is: 2024-11-19 06:28:36