[ kish @ 20.02.2009. 14:00 ] @
Dakle, projekat ima sledecu strukturu:
main.cpp:
Code:

#include <iostream>
#include "test1.h"
#include "test2.h"
using namespace std;

int main()
{
    set();
    cout << "testint = " << testint << endl;
    return 0;
}


test1.h:
Code:

#ifndef TEST1_H
#define TEST1_h

void set();

#endif


test1.cpp:
Code:

#include "test1.h"
#include "test2.h"

void set() {
    testint=1;
}


test2.h:
Code:

#ifndef TEST2_H
#define TEST2_H

int testint;

#endif


Pri kompajliranju dobijam sledecu gresku:
Code:

Compiling: main.cpp
Linking console executable: C:\Trash\coding\c++\htest\console.exe
.objs\main.o:main.cpp:(.bss+0x0): multiple definition of `testint'
.objs\test1.o:test1.cpp:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)


Izgleda da kompajler pokusava dva puta da definise promenjivu testint, medjutim TEST2_H bi bas to trebao da spreci. U cemu je tacno problem? Unapred hvala.
EDIT: Sad vidim da ima i poseban podforum za c++. Nek se tema prebaci na svoje mesto. Sorry.

[Ovu poruku je menjao kish dana 20.02.2009. u 15:17 GMT+1]
[ Mihajlo Cvetanović @ 20.02.2009. 23:05 ] @
Stavi "int testint;" u cpp, a "extern int testint;" u heder.
[ kish @ 21.02.2009. 15:10 ] @
Radi. Zahvaljujem.