[C++] Linker error.

Pagina: 1
Acties:

  • AuC
  • Registratie: Januari 2003
  • Laatst online: 10-07 15:00
Hey mensen,

Ik ben vandaag eens wat aan het klummelen met MFC, simpel programmatje aan het maken. Nu heb ik het volgende probleem:

Als ik het volgende in stdafx.h declareer:

code:
1
2
3
4
5
struct OPTIONS {
    int iSaveImageAs;
};

OPTIONS ProgramOptions;


krijg ik de volgende error:

code:
1
2
3
StdAfx.obj : error LNK2005: "struct OPTIONS ProgramOptions" (?ProgramOptions@@3UOPTIONS@@A) already defined in ScreenerDlg.obj
OptionsDialog.obj : error LNK2005: "struct OPTIONS ProgramOptions" (?ProgramOptions@@3UOPTIONS@@A) already defined in ScreenerDlg.obj
Debug/Screener.exe : fatal error LNK1169: one or more multiply defined symbols found


Iemand enig idee wat ik fout doe, en hoe ik dit oplos? (waarschijnlijk een dom foutje, maar ik kom er echt niet uit.)

  • klinz
  • Registratie: Maart 2002
  • Laatst online: 10-08 15:44

klinz

weet van NIETS

Je hoort geen variabelen te declareren in .h files. Alleen de definities kun je daar kwijt. Dus
code:
1
2
3
struct OPTIONS {
    int iSaveImageAs;
};

Zet je in een include file (.h) en:
code:
1
OPTIONS ProgramOptions;

in een source file (.cpp)

  • AuC
  • Registratie: Januari 2003
  • Laatst online: 10-07 15:00
Thnx :) nu kan ik weer verder.

  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 21-08 17:14
Klein puntje: je mag ze wel declareren, alleen niet definieren:

code:
1
2
3
4
5
struct OPTIONS {
    int iSaveImageAs;
};

extern OPTIONS ProgramOptions;

Dan moet je wel in een .cpp file alsnog OPTIONS ProgramOptions; definieren,
maar je kunt wel ProgramOptions overal gebruiken.

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

MSalters schreef op 23 August 2003 @ 12:57:
Klein puntje: je mag ze wel declareren, alleen niet definieren:
Kan aan mij liggen, maar header files zijn juist bedoeld om de declareren en te definieren. In headers mag je niet instantieren :z

Professionele website nodig?


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 04:06

.oisyn

Moderator Devschuur®

Demotivational Speaker

Een variabele definieren is instantieren :)
met extern declareer je alleen maar

Goed, een class/struct kun je natuurlijk wel definieren, maar volgens mij doelde MSalters dan ook meer op het feit dat klinz de termen omdraaide :)

.edit: anyway, what in earth heeft dit met PHP te maken :?

[ Voor 12% gewijzigd door .oisyn op 23-08-2003 17:17 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • MSalters
  • Registratie: Juni 2001
  • Laatst online: 21-08 17:14
Instantieren doe je met templates.

Vuistregel:
"Declareren" = "Er is ... "
"Definieren" = "Hier is ..."

Declaraties mag je dus herhalen, definities niet. klinz had ze idd dus verkeerd om.

Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein


  • Soultaker
  • Registratie: September 2000
  • Laatst online: 01:56
MSalters schreef op 25 augustus 2003 @ 00:29:
Instantieren doe je met templates.
En met typen: new FooBar, of new int[10] bijvoorbeeld.

</mierenneuken>

  • alienfruit
  • Registratie: Maart 2003
  • Laatst online: 07:56

alienfruit

the alien you never expected

Iemand eigenlijk enig idee wat ze bedoelen met "Foo" ik vraag het me al tijden af. :)

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 18-08 21:00

Creepy

Tactical Espionage Splatterer

alienfruit schreef op 25 August 2003 @ 03:21:
Iemand eigenlijk enig idee wat ze bedoelen met "Foo" ik vraag het me al tijden af. :)
offtopic:
foobar n.
[very common] Another widely used metasyntactic variable;see foo for etymology. Probably originally propagated through DECsystem manuals by Digital Equipment Corporation (DEC) in 1960s and early 1970s; confirmed sightings there go back to 1972. Hackers do not generally use this to mean FUBAR in either the slang or jargon sense. See also Fred Foobar. In RFC1639, "FOOBAR" was made an abbreviation for "FTP Operation Over Big Address Records", but this was an obvious backronym.

metasyntactic variable
A name used in examples and understood to stand for whatever thing is under discussion, or any random member of a class of things under discussion. The word foo is the canonical example. To avoid confusion, hackers never (well, hardly ever) use `foo' or other words like it as permanent names for anything. In filenames, a common convention is that any filename beginning with a metasyntactic-variable name is a scratch file that may be deleted at any time.

Metasyntactic variables are so called because (1) they are variables in the metalanguage used to talk about programs etc; (2) they are variables whose values are often variables (as in usages usages like "the value of f(foo,bar) is the sum of foo and bar"). However, it has been plausibly suggested that the real reason for the term "metasyntactic variable" is that it sounds good.

(Bron: www.jargon.org)
Zie ook http://www.catb.org/~esr/jargon/html/F/foo.html

:P

[ Voor 5% gewijzigd door Creepy op 25-08-2003 08:20 ]

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


  • alienfruit
  • Registratie: Maart 2003
  • Laatst online: 07:56

alienfruit

the alien you never expected

Aha. Hendig, stond niet in me engels woordenboek namelijk :)

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 04:06

.oisyn

Moderator Devschuur®

Demotivational Speaker

Soultaker schreef op 25 augustus 2003 @ 02:33:
[...]

En met typen: new FooBar, of new int[10] bijvoorbeeld.

nog meer gemierenneuk: new is natuurlijk niet nodig voor een instantiatie, vandaar de opmerking van curry

MijnKlasse mijnInstantie; is natuurlijk ook een instantiatie ;)

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • demonite
  • Registratie: April 2000
  • Laatst online: 29-05 08:55

demonite

the way is up

nogmeer offtopic: ik dacht dat foobar afstamde van fubar wat stond voor fucked up beyond all repair

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

offtopic:
Fucked Up Beyond All Recognition dus... Zal ik dit topic maar eens gaan renamen naar [C++] Kom hier hopeloos offtopic meeneuzelen of zo? :Y)

Professionele website nodig?

Pagina: 1