- 1
- 2
- 3
- 4
- 5
int i=1;
Console.WriteLine((i+null)==null); //True
Console.WriteLine(1+null); //1
Console.WriteLine(null+1); //1
Console.WriteLine((1+null).GetType()); //System.Int32
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
int i=1;
Console.WriteLine((i+null)==null); //True
Console.WriteLine(1+null); //1
Console.WriteLine(null+1); //1
Console.WriteLine((1+null).GetType()); //System.Int32
http://ideone.com/LomfRC
+1
for (conn_vector::iterator i = m_connections.begin(); i != m_connections.end(); ++i) {
if (*i == conn) {
m_connections.erase(i);
toDelete = *i;
break;
}
}
Да, С++98. Да, в std::find не умеем. Да, сегфолт. Да, моё.
+1
chunksLst.erase(++it1);
+1
struct Vector2f{float x, y;};
struct Vector3f{float x, y, z;};
struct Tensor3f{float xx, xy, xz, yy, yz, zz;};
struct Matrix3x3f{float data[9];};
struct Space2
{
typedef Vector2f Vector;
};
struct Space3
{
typedef Vector3f Vector;
};
template<typename Space>
struct ParticleSystem
{
template<typename T>
struct ParticleData{};
template<>
struct ParticleData<Space2>
{
float orientation;
float invInertia;
};
template<>
struct ParticleData<Space3>
{
typename Matrix3x3f orientation;
typename Tensor3f inertiaTensor;
};
struct Particle : public ParticleData<Space>
{
typename Space::Vector pos, velocity;
};
template<typename T>
void DumpParticle(){}
template<>
void DumpParticle<Space2>()
{
printf("%f %f", particles[0].orientation, particles[0].invInertia);
}
template<>
void DumpParticle<Space3>()
{
printf("%f %f", particles[0].orientation.data[0], particles[0].inertia.xx);
}
void DumpParticles()
{
DumpParticle<Space>();
}
std::vector<Particle> particles;
};
Хочу объединить трехмерный и двухмерный движок.
+1
std::AIDS
+1
void gte::loadProps(const char* fileName){
propMap.clear();
s3eFile* g_FileHandle = s3eFileOpen(fileName, "rb");
while (!s3eFileEOF(g_FileHandle)) {
char c1=0;
char c2=0;
s3eFileRead(&c1, 1, 1, g_FileHandle);
s3eFileRead(&c2, 1, 1, g_FileHandle);
int len = 0;
len = (c2 & 0xFF) | ( (c1 & 0xff) << 8);
if (len==0) continue;
char* textData = new char[len+1];
textData[len] = 0;
s3eFileRead(textData, sizeof(char), len, g_FileHandle);
char* pos = strchr(textData, ':');
string key(textData, pos - textData);
string value(pos + 2, textData + len - pos - 2);//(textData,
propMap[key] = value;
}
s3eFileClose(g_FileHandle);
}
Чтение строки, первые 2 байта - длинна.
Проект использует Marmalade SDK.
+1
int main()
{
__asm()
{
NOP
}
return 0;
}
программа делает ничего, но делает
+1
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
class radian
{protected:
double x;
public:
radian();//конструктор без параметров, возвращает дежурное значение
radian(double x1);//конструктор с параметрами
radian sum_rad(radian a );
radian unsum_rad(radian a);//разность 2-х радиан
double get_r(){return x;}//нужный геттр
void set_r(double x1);//бесполезный сеттрер
double radian::quarter(radian a);//определение четверти угла заданного в радианах
double operator *();//перегрузка операции. возводит во вторую степень
double radian::rad_to_grad();//перевод из радиан в градусы
~radian();//деструкторуу
};
class namerad:public radian
{
private:
string name;
public:
namerad::namerad(double corner,string name)
{set_name(name);}
void namerad::set_name(string newname)
{name=newname;}
void namerad::get_name(string currentname)
{currentname=name;}
};
radian::radian()//конструктор по умолчанию
{
x=0;
}
radian::radian(double x1)//конструктор с 1 параметром
{
x=x1;
}
radian radian::sum_rad(radian a)//сумма 2-х радиан
{radian n(x+a.x);
return n;
}
void radian::set_r( double x1)//сеттер
{ x=x1;}
radian::~radian() {x=0;}//деструктор
radian radian::unsum_rad(radian a)//разность 2-х радиан
{radian n(x-a.x);
return n;
}
double radian::rad_to_grad() //перевод из радиан в градусы
{
return(x*(180/3.14));
}
double radian ::operator *()//перегрузка операции
{
return x*x;
}
double radian::quarter(radian a)//определение четверти угла заданного в радианах
{while(a.x>6.28){a.x-=6.28;}
if ((a.x >=0)&&(a.x<=1.57)) return 1;
if ((a.x>=1.57)&&(a.x<=3.14)) return 2;
if ((a.x>=3.14)&&(a.x<=4.71)) return 3;
return 4;
}
int main()
{
radian a,b,c(5.0),d(6.20);
cout<<"summa=";b=c.sum_rad(d);cout<<b.get_r() << endl;//сумма
cout<<"raznost=";b=d.unsum_rad(c);cout<<b.get_r() << endl; //разность
cout<<"chetvert: ";cout<< d.quarter(d) << endl;//четверть
cout<<"iz radian v gradusi: ";cout<<d.rad_to_grad() << endl;//перевод из радиан в градусы
cout<<"peregruz sqr "<<*c;//возведение в квадрат. перегруженная операция
system ("PAUSE");
return 0;
}
+1
class SumClass
{
int A, B;
public:
void Set_A(int A) {this->A = A;}
void Set_B(int B) {this->B = B;}
int Sum() {return A+B;}
}
class MultiSumClass
{
SumClass Sum;
int count;
public:
void Set_A(int A) {Sum.Set_A(A);}
void Set_B(int B) {Sum.Set_B(B);}
void Set_Count(int count) {this->count = count;}
int GetSum() {return Sum->Sum()*count;}
}
void main()
{
MultiSumClass MSC;
MSC.Set_A(5); MSC.Set_B(10);
MSC.Set_Count(2);
cout << MSC.GetSum();
}
Вот зачем ООП нужно
http://www.gamedev.ru/flame/forum/?id=164035
извените за игрстрй
+1
WORD StrLen(PChar s)
{
ASSERT(s!=NULL);
int i;
for (i=0; ( (*(s+i)!=0) && (i<=WORDMAX) ); i++) {};
ASSERT(i<=WORDMAX);
return (WORD)i;
};
По заявкам из http://govnokod.ru/11318