Похоже, вы хотите объединить те объекты, которые имеют одинаковый индекс во входных массивах:
function merge(a, b) {
const merged = [];
for (let i = 0; i < a.length || i < b.length; i++) {
merged.push(a[i] && b[i] ? {...a[i], ...b[i]} : a[i] || b[i]);
}
return merged;
}
console.log(merge([null,null,{a:1}], [{c:3},null,{a:3,b:2}]));
console.log(merge([], [null,null,{t:4}]));
Это не плагин Rails, dll, которая экспортирует экземпляр GArray.
#ifdef LGI_DLL
#define LgiClass __declspec(dllexport)
#else
#define LgiClass __declspec(dllimport)
#endif
class LgiClass GToken : public GArray<char*>
{
/// stuff...
};
Решение:
Включите этот заголовок GToken в мой EXE-файл, в частности файл FrameStore.cpp, который использует реализацию GArray, тогда компиляция будет импортировать эти символы из DLL вместо дублирования их
Было бы неплохо, если бы компилятор дал мне больше подсказки о том, где DLL определяет символ. Простое высказывание «где-то дубликат» не очень полезно.
Если вы используете Visual Studio 6, убедитесь, что установлена следующая опция:
Проект-> Настройки -> C / C ++ -> Генерация кода-> Использовать библиотеку времени выполнения ===> Отладка многопоточной / многопоточной
РЕДАКТИРОВАТЬ: В VS 2005 это в основном то же самое.
Проект-> Свойства-> Свойства конфигурации-> C / C ++ -> Генерация кода-> Библиотека времени выполнения-> Многопоточная / Многопоточная отладка
Как примечание, вы можете разделить ваши объявления и определения, так что это не так ужасно:
template <class Type>
class GArray
{
Type *p;
uint32 len;
uint32 alloc;
protected:
bool fixed;
public:
GArray(int PreAlloc = 0);
/// Destructor
~GArray() {Length(0);}
/// Returns the number of used entries
int Length() {return len;}
/// Sets the length of available entries
bool Length(uint32 i);
// etc...
};
template <class Type>
GArray<Type>::GArray(int PreAlloc = 0)
{
p = 0;
len = 0;
fixed = false;
alloc = PreAlloc;
if (alloc)
{
int Bytes = sizeof(Type) * alloc;
p = (Type*) malloc(Bytes);
if (p)
{
memset(p, 0, Bytes);
}
else
{
alloc = 0;
}
}
}
template <class Type>
bool GArray<Type>::Length(uint32 i);
{
if (i > 0)
{
if (i > len && fixed)
return false;
uint nalloc = alloc;
if (i < len)
{
// Shrinking
}
else
{
// Expanding
int b;
for (b = 4; (1 << b) < i; b++)
;
nalloc = 1 << b;
LgiAssert(nalloc >= i);
}
if (nalloc != alloc)
{
Type *np = (Type*)malloc(sizeof(Type) * nalloc);
if (!np)
{
return false;
}
if (p)
{
// copy across common elements
memcpy(np, p, min(len, i) * sizeof(Type));
free(p);
}
p = np;
alloc = nalloc;
}
if (i > len)
{
// zero new elements
memset(p + len, 0, sizeof(Type) * (i - len));
}
len = i;
}
else
{
if (p)
{
int Length = len;
for (uint i=0; i<Length; i++)
{
p[i].~Type();
}
free(p);
p = 0;
}
len = alloc = 0;
}
return true;
}
// вы получаете точку
Кроме того, operator =
должен взять const GArray
, чтобы указать, что правая часть не изменяется.
2>lgi8d.lib(Lgi8d.dll) : error LNK2005: "public: int __thiscall GArray<char *>::Length(void)" (?Length@?$GArray@PAD@@QAEHXZ) already defined in FrameStore.obj
2>D:\Home\matthew\network_camera\src\vod_test\Debug\vod_test.exe : fatal error LNK1169: one or more multiply defined symbols found
lgi8d.lib
and vod_test.exe
are two separate binaries. The problem might lie in the fact that the .lib
already defines the symbol which the .exe is defining again.
Вы можете попробовать добавить declspec (dllexport) к классу в DLL и declspec (dllimport) в EXE. Например,
#if !defined(MYDLLEXPORT)
// We are users of, and *importing* the library routines...
#define MYLIB_SPEC __declspec(dllimport)
#else
// We are building and exporting the library routines...
#define MYLIB_SPEC __declspec(dllexport)
#endif
// ...
template<typename Type>
class MYLIB_SPEC GArray // ...
Затем убедитесь, что MYDLLEXPORT определен в проекте, который создает DLL, и не определен для EXE.
AFAIK, хотя обычно вам это не нужно для шаблонов.
Подробнее о declspec здесь: http://msdn.microsoft.com/en-us/library/a90k134d (VS.80) .aspx .
Почему бы вам не использовать вместо него std :: vector?