Public Group

Archived

This topic is now archived and is closed to further replies.

unresolved external symbol error with vectors.....

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have this in my common.h header file: #include "StdAfx.h" extern int TotalNumHourly,TotalNumCommission,TotalNumSalary; extern double TotalPayHourly,TotalPayCommission,TotalPaySalary; struct DataRecord { bool Hourly,Commission,Salary; char LastName [100]; char FirstName [100]; char Address [100]; char City [100]; char State [25]; char Zip [25]; char sex [25]; char SorM [25]; char YofS [25]; char Ssn [25]; char Age [25]; double STotalPay, SBonus, SSalary; double HHoursWorked, HHourlyRate, HRegularPay; double Crate,CItemsSold,CPricePerItem,CTotal; }; extern std::vector Vdata; then in a later function I tried to use that vector(AddEmp.cpp): else { DataRecord * ptr = new DataRecord; strcpy(ptr->LastName,cap_lname); strcpy(ptr->FirstName,cap_fname); strcpy(ptr->City,cap_City); strcpy(ptr->State,cap_State); strcpy(ptr->Address,cap_Address); strcpy(ptr->Zip,cap_Zip); strcpy(ptr->Age,cap_Age); strcpy(ptr->sex,cap_Sex); strcpy(ptr->SorM,cap_Mos); strcpy(ptr->YofS,cap_Ywc); Vdata.push_back(ptr); CDialog::OnOK(); } If I declare the vector inside AddEmp.cpp I get no errors, but when I declare it in common.h as I have posted above I get this error: unresolved external symbol "class std::vector > Vdata" (?Vdata@@3V?$vector@PAUDataRecord@@V?$allocator@PAUDataRecord@@@std@@@std@@A) any ideas of what I can do?

Share on other sites
Why not just turn your struct into a class, and create a Copy function or overload the = operator?

Share on other sites
quote:
Original post by Fruny
Look up the semantics for extern.

You still have to define your variable in a (single) source file.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

I looked up extern at msdn, it told me nothing that I dont already know... In order to declare my vector in a single source file I should write something in common.ccp, correct? What would I write? the variable is already declared and I dont need to preset any values..

thanks for your help guys, it is very much appreciated

Share on other sites
quote:
In order to declare my vector in a single source file I should write something in common.ccp, correct? What would I write? the variable is already declared and I dont need to preset any values..

The variable is declared, but not defined. It''s just like giving a function prototype but not the function. You still have to define the variable, like any other global variable in common.cpp. The extern declaration only affects the visibility of the variable, not its existence.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share on other sites
quote:
Original post by Fruny
The variable is declared, but not defined. It''s just like giving a function prototype but not the function. You still have to define the variable, like any other global variable in common.cpp. The extern declaration only affects the visibility of the variable, not its existence.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Thanks a lot, I was still a little unsure of how externs work but now after reading that I completely understand. Thanks again,

• 10
• 15
• 14
• 18
• 15
×

Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!