Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 105181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:23:55+00:00 2026-05-11T01:23:55+00:00

I have the below code in stdafx.h. using namespace std; typedef struct { DWORD

  • 0

I have the below code in stdafx.h.

using namespace std;  typedef struct {     DWORD   address;     DWORD   size;     char    file[64];     DWORD   line; } ALLOC_INFO;  typedef list<ALLOC_INFO*> AllocList; //AllocList *allocList; 

Without the commented code (last line), it compiles just fine. But when I add the commented code, Im getting the following error.

error LNK2005: ‘class std::list > * allocList’ (?allocList@@3PAV?$list@PAUALLOC_INFO@@V?$allocator@PAUALLOC_INFO@@@std@@@std@@A) already defined in test.obj

Im using Visual Studio .NET 2003. Anyone has any idea what that is and how to solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:23:56+00:00Added an answer on May 11, 2026 at 1:23 am

    Don’t put definitions in header files, just declarations. Declarations specify that something exists while definitions actually define them (by allocating space). For example typedef, extern and function prototypes are all declarations, while things like struct, int and function bodies are definitions.

    What’s happening is that you’re most likely including stdafx.h in multiple compilation units (C++ source files) and each of the resulting object files is getting its own copy of allocList.

    Then when you link the objects together, there’s two (or more) things called allocList, hence the link error.

    You would be better off declaring the variable:

    extern AllocList *allocList; 

    in your header file and defining it somewhere in a C++ source file (such as a main.cpp):

    AllocList *allocList; 

    That way, every compilation unit that includes stdafx.h will know about the external variable, but it’s only defined in one compilation unit.

    Based on your further information:

    I was trying to follow http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml, I assume that all those code are meant to be placed in the stdafx.h. Any other alternatives, pax?

    My response is as follows.

    I wouldn’t put them in stdafx.h myself since I think that uses some MS magic for pre-compiled headers.

    Make a separate header file mymemory.h and put your function prototypes in it, for example (note that this has no body):

    inline void * __cdecl operator new(     unsigned int size,     const char *file,     int line); 

    Also in that header, put the other prototypes for AddTrack(), DumpUnfreed(), etc., and the #define, typedef and extern statements:

    extern AllocList *allocList; 

    Then, in a new file mymemory.cpp (which also contains #include 'mymemory.h'), put the actual definition of allocList along with all the real functions (not just the prototypes) and add that file to your project.

    Then, #include 'mymemory.h' in every source file in which you need to track memory (probably all of them). Because there are no definitions in the header file, you won’t get duplicates during the link and because the declarations are there, you won’t get undefined references either.

    Keep in mind that this won’t track memory leaks in code that you don’t compile (e.g., third-party libraries) but it should let you know about your own problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 84k
  • Answers 84k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Oracle 8i is very old. I believe 1999 or 2000.… May 11, 2026 at 5:00 pm
  • Editorial Team
    Editorial Team added an answer You could allow certain directories (directly under <configuration>): <location path="images">… May 11, 2026 at 5:00 pm
  • Editorial Team
    Editorial Team added an answer A similar thread is here: http://www.linkedin.com/answers/technology/software-development/TCH_SFT/291114-19420164?browseCategory=TCH_SFT Reproduced here: So long… May 11, 2026 at 5:00 pm

Related Questions

I have a utility (grep) that gives me a list of filenames and a
I am using SQLite3 for iPhone development and I'm attempting to wrap a few
I have implemented the MOD 10 check digit algorithm using SQL, for the US
I have a view that I want to add some custom drawing to. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.