- 1
- 2
bool operator()(int x,int y)
{return x<y;}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−33
bool operator()(int x,int y)
{return x<y;}
Вторая часть) реально интересуются люди
"надо два объекта моего класса сравнить, так?"
ну, вообще жесть
−25
bool operator<(const A *obj){
if (obj->n < this->n)
return true;
else if (this->n < obj->n)
return false;
};
Перегрузка оператора сравнения
−27
class Screen
{
private:
unsigned char *data; // do not move
size_t size; // do not move
−42
#include <iostream>
using namespace std;
int main()
{
for(int i = 0x1; 0x1 <= i; i++)
{
int a = 0x5;
int b = 0xa;
cin >> i;
if(b || a)
{
a += 0x5;
cout << "\n ";
cout << "первое условие: ";
cout << "\n ";
cout << "переменная a = " << a;
cout << "\n ";
cout << "переменная b = " << --b + 0x5 - 0x9;
cout << "\n";
goto var;
}
else
{
var:
cout << "\n ";
cout << "второе условие: ";
a = (0xa - 0x5);
cout << "\n ";
cout << "переменная a = " << a;
cout << "\n ";
cout << "переменная b = " << ++b;
cout << "\n";
}
break;
}
system("pause");
return 0;
}
Попросил чела решить классическую задачку - обменять значениями две переменные, не используя третьей
−33
CArray <CStyle *, CStyle *> m_aStyles;
...
#define RETURN_TRUE return *bOk = TRUE, S_OK
#define RETURN_FALSE return *bOk = FALSE, S_FALSE
#define RETURN_ERROR(E) \
return LastErrorCode = (ERROR_##E), *bOk = FALSE, S_FALSE
...
// Создание нового стиля (пустого)
STDMETHODIMP CEffector::AddStyle(VARIANT_BOOL *bOk)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
CStyle *pNew = new CStyle;
if (pNew)
{
INT n = m_aStyles.GetSize();
m_aStyles.Add(pNew);
if (m_aStyles.GetSize() <= n)
RETURN_ERROR(MEMORY);
}
else
RETURN_ERROR(MEMORY);
RETURN_TRUE;
}
...
// Получение кода ошибки
STDMETHODIMP CEffector::GetErrorCode(long *p)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
*p = LastErrorCode;
LastErrorCode = ERROR_NONE;
return S_OK;
}
Мой первый COM-объект.
1) Если при успешном возвращении метод должен возвращать S_OK, то при ошибке... S_FALSE, наверное.
2) Только в Дельфи почему-то возвращается не HRESULT, а параметр, помеченный [out]. Поэтому пришлось добавить аргумент *bOk.
3) Интересно, что делает CArray, когда кончается память.
−34
//cgi_http.cpp
#include "http.h"
#include <cstring>
#include <cstdlib>
//decodes uri-encorded string
char* uri_decode(char* source, char* dest)
{
//save pointer address for dest
char* p = dest;
char* src = source;
while(*src)
{
if(src == strstr(src,"%B8"))
{
*p = 'ё';
src = src + 3;
p++;
}
else if(src == strstr(src,"%E9"))
{
*p = 'й';
src = src + 3;
p++;
}
else if(src == strstr(src,"%F6"))
{
*p = 'ц';
src = src + 3;
p++;
}
else if(src == strstr(src,"%F3"))
{
*p = 'у';
src = src + 3;
p++;
}
else if(src == strstr(src,"%EA"))
{
*p = 'к';
src = src + 3;
p++;
}
else if(src == strstr(src,"%E5"))
{
*p = 'е';
src = src + 3;
p++;
}
.......
Выкладываю свой чатик на С++. PHP не нужен.
−35
#ifndef _PERSISTENT_COLLECTION_CPP
#define _PERSISTENT_COLLECTION_CPP
////// BASE_CLASS
#include "Persistent/ObjectP.cpp"
////// Support
#include "Persistent/UInt.cpp"
////// Persistent Level 1
#include "Persistent/StringP.cpp"
#include "Persistent/UIntP.cpp"
#include "Persistent/TimeP.cpp"
#include "Persistent/StringArrayP.cpp"
#include "Persistent/BoolP.cpp"
#include "Persistent/Int64P.cpp"
#include "Persistent/BinaryP.cpp"
////// Persistent Level 2
#include "Persistent/MapStringToObjectPPtr.cpp"
#include "Persistent/ObjectPArrayPtr.cpp"
#include "Persistent/ObjectPListPtr.cpp"
////// Persistent Level 3
#include "Persistent/PropertySet.cpp"
#endif
Лолшто? Include cpp? 0_o
−30
BOOL CIniFile::LoadIniFile()
{
CString csBuff;
CFile oIniFile;
if (oIniFile.Open(csIniFileName, CFile::modeRead))
{
ULONGLONG lenReal = oIniFile.GetLength();
DWORD dwLen = (DWORD) lenReal;
if (lenReal > UINT_MAX)
{
dwLen = UINT_MAX;
TRACE("ERROR: CIniFile::LoadIniFile(); CFIle::GetLength() > UINT_MAX\n;");
ASSERT(0);
}
if (!dwLen)
return FALSE;
boost::scoped_array <char> cBuffer(new char[dwLen]);
oIniFile.Read(cBuffer.get(), dwLen);
LoadIniFromBuffer(cBuffer.get(), dwLen);
oIniFile.Close();
if (GetCountRecords())
return TRUE;
}
return FALSE;
}
boost::scoped_array... nuff said =(
−43
bool ok = (state == 0) ? false : true;
И это пишет человек, пишущий на плюсах уже много лет...
−34
int ConditionsTuple(const bool Condition1, const bool Condition2)
{
return (Condition1<<1) + Condition2;
}
template <bool Condition1, bool Condition2>
struct TConditionsTuple
{
enum {Result = (Condition1<<1) + Condition2};
};
float SignedIf(const bool Condition)
{
return Condition ? -1 : 1;
}
switch (ConditionsTuple(
bExpr1,
bExpr2
))
{
case TConditionsTuple<1, 1>::Result:
return PArc(new TArc(
CouplePointAtPrimitive1,
CouplePointAtPrimitive2,
ArcCoupleCenter,
Abs(arcCoupleRadius)
));
case TConditionsTuple<0, 1>::Result:
throw TPrimitive1HalfLengthExpiredException();
case TConditionsTuple<1, 0>::Result:
throw TPrimitive2HalfLengthExpiredException();
case TConditionsTuple<0, 0>::Result:
throw TAllPrimitivesHalfLengthExpiredException();
}