A potential bug? (- warning LNK4227)

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi,

I've been recently porting some software written under
VC++ 6.0 to VC .NET. The software was compiling fine
under 6.0 but under .NET I'm getting linker warning:

b.obj : warning LNK4227: metadata operation warning
(00131189) : Inconsistent parameter information in
duplicated methods (methods: new; type: <Module>):
(0x08000005).

I tried to isolate the problem. I created simple
project Test - console application. The only thing
I changed in project settings was disabling the use
of precompiled headers.

There are also three other files: a.h (template Ta)
and b.h/b.cpp (class Cb). Below is the source code.

When I compile the whole project, I'm getting linker
warning LNK4227. The interesting thing is that when
the method Alloc() of Ta is not "virtual" (delete
"virtual" word) everything compiles and links without
problem. Similarly, when the method's body contains
only "return m_pT = new T;" and the function remains
"virtual" the linker doesn't have any problem.

But I do need to use "malloc" and "new() T" for
_separate_ memory allocation and object
initialization (in real code), and the method
Alloc() must be virtual...

Does anyone know what am I doing wrong? How can
setup the compiler or fix the code to get rid of
the warning? Or maybe there is a bug in VC++?

I would greatly appreciate your suggestions.

Thanks,
Piotr Balcerzak


Test.cpp
-----------------------------------------------------------------
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"
#include "a.h"

#using <mscorlib.dll>
using namespace System;

int _tmain()
{
a<char> xyz;

Console::WriteLine(S"Hello World");
return 0;
}
-----------------------------------------------------------------

a.h
-----------------------------------------------------------------
#include <wtypes.h>
#include <new.h>

template<class T>
class Ta
{
private:
T* m_pT; //memory block containing objects

public:
Ta() : m_pT(NULL) {}
virtual ~Ta() { Free(); }

virtual T* Alloc(void) //allocate memory
{
m_pT = (T*)malloc(sizeof(T));
if (m_pT != NULL) new (m_pT) T; //call constructor
return m_pT;

// return m_pT = new T; //works here but is useless in my code
}

virtual void Free(void) //free memory
{
if (m_pT != NULL)
{
m_pT->~T(); //call destructor
free(m_pT);
}
}
};
-----------------------------------------------------------------

b.h
-----------------------------------------------------------------
#include "a.h"

class Cb
{
private:
Ta<char> x;

public:
Cb();
~Cb();
};
-----------------------------------------------------------------

b.cpp
-----------------------------------------------------------------
#include "b.h"

Cb::Cb()
{
int i = 0;
}

Cb::~Cb()
{
int i = 0;
}
-----------------------------------------------------------------
 
Back
Top