-
+69.5
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
#include <iostream>
using namespace std;
class MyException
{
public:
MyException(char *msg) { m_msg = msg; }
~MyException(){}
char *GetError(){return m_msg;}
protected:
char *m_msg;
};
int main()
{
int *buffer;
try
{
buffer = new int[255];
if (buffer == NULL)
{
MyException *exception =
new MyException("Memory allocation failed!");
throw exception;
}
else
delete buffer;
}
catch (MyException *exception)
{
char *msg = exception->GetError();
cout << msg << endl;
}
return 0;
}
Книга "Использование Viusal C++" Кейт Грегори. Глава 24 о предотвращении утечек памяти и работе с исключениями.
ccoder,
20 Февраля 2010
-
+168.5
- 1
- 2
- 3
- 4
- 5
- 6
for ($i=0; $i<count($t__); $i++)
{
$i++;
fnc_pars($t__[($i-1)], $pr_i2[($i-1)]);
$i= $i-1;
}
Прогон по массиву )))
pasha,
19 Февраля 2010
-
+73.6
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
private void applyFilter(Article article, List<Article> allArticles, RSSFilter filter) {
if (filter != null) {
if ((filter.isAnd()) && (filter.isContent()) && (filter.isTitle())) {
if (article.getTitle().toLowerCase().contains(filter.getFilter().toLowerCase())
&& (article.getContent().toLowerCase().contains(filter.getFilter()
.toLowerCase()))) {
allArticles.add(article);
}
}
if (filter.getFilter() == null || filter.getFilter().isEmpty()) {
allArticles.add(article);
} else if ((filter.isAnd()) && (!filter.isContent()) && (filter.isTitle())) {
if (article.getTitle().toLowerCase().contains(filter.getFilter().toLowerCase())) {
allArticles.add(article);
}
} else if ((filter.isAnd()) && (filter.isContent()) && (!filter.isTitle())) {
if (article.getContent().toLowerCase().contains(filter.getFilter().toLowerCase())) {
allArticles.add(article);
}
} else if ((!filter.isAnd() && !filter.isContent()) && (filter.isTitle())) {
if (article.getTitle().toLowerCase().contains(filter.getFilter().toLowerCase()))
allArticles.add(article);
} else if ((!filter.isAnd()) && (!filter.isTitle()) && (filter.isContent())) {
if (article.getContent().toLowerCase().contains(filter.getFilter().toLowerCase()))
allArticles.add(article);
} else if (!filter.isAnd()) {
if (article.getTitle().toLowerCase().contains(filter.getFilter().toLowerCase())
|| (article.getContent().toLowerCase().contains(filter.getFilter()
.toLowerCase()))) {
allArticles.add(article);
}
}
} else {
allArticles.add(article);
}
}
стыдно, млин у себя нашел)))
реализация фильтра
взаимоисключение, нереальные условия (UI на радиобатонах)
fisherman,
19 Февраля 2010
-
+65.7
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
template <class T>
struct SLinkedListNode
{
public:
SLinkedListNode* m_pPrev; ///< Pointer to previous node.
SLinkedListNode* m_pNext; ///< Pointer to next node.
int Initialize();
int Finalize();
};
...
struct SWaiterNode : public SLinkedListNode<SContainerNode>, public SLinkedListNode<SWaiterListNode>
{
...
// container node
struct SContainerNode
{
// no members needed yet (just for masking SLinkedListNode type)
};
// container
struct SContainer
{
public:
SLinkedListNode<SContainerNode>* m_pObjects;
сначала делаем тимплейтный класс, параметр которого никому не нужен, а потом делаем заглушку для этого параметра.
нормально.
kubrinsky,
19 Февраля 2010
-
+166.3
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
<?php
if (($_COOKIE["prava"]==1)or($_COOKIE["prava"]==2))
{
$lstclient[]=mysql_query("select * from lstclient ");
$lstclient[]=mysql_query("select * from lstclient ");
$lstclient[]=mysql_query("select * from lstclient ");
$lstclient[]=mysql_query("select * from lstclient ");
$lstcou[]=mysql_query("select * from lstcou ");
$lstcou[]=mysql_query("select * from lstcou ");
$lstcou[]=mysql_query("select * from lstcou ");
$lstcou[]=mysql_query("select * from lstcou ");
$lstcou[]=mysql_query("select * from lstcou ");
/* ... и так еще два десятк строк ... */
echo'<tr><td>Страны</td><td>';
while($mas=mysql_fetch_row($countcou)){$counter=$mas[0];}
while($maslnk=mysql_fetch_row($lnkcou)){$coulnk[]=$maslnk[0];}
for ($i=1; $i<6; $i++)
{
echo' <select name="cou'.$i.'"><option value="0"> </option>';
while($mas=mysql_fetch_row($lstcou[$i-1]))
{
if ($i>$counter)
{
echo '<option value="'.$mas[0].'">'.$mas[1].'</option>';
}
else
{
if ($coulnk[$i-1]<>$mas[0]){echo '<option value="'.$mas[0].'">'.$mas[1].'</option>';}
else {echo '<option selected value="'.$mas[0].'">'.$mas[1].'</option>';}
}
}
echo'</select>';
}
echo'
</td>
</tr>
';
И подобного альтернативно-одаренного творчества там 150Кб (простейший CRUD, с одной таблицей)
turdman,
19 Февраля 2010
-
+149.1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<?php
$menu = & JSite::getMenu();
$flag = ($menu->getActive() == $menu->getDefault());
$option = JRequest::getVar('option', null);
?>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
<!--[if lte IE 7]>
<script language="JavaScript" type="text/javascript" src="?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/DD_belatedPNG.js"></script>
<script language="JavaScript" type="text/javascript">
DD_belatedPNG.fix('.icon a, .phone, .menu a, .header ');
</script>
<![endif]-->
</head>
<body >
<div class="wrapper">
<div class="header">
<ul class="icon">
<li class="<?php if ($flag) {?>active<?php }?>"><a href="#" class="home"><span></span></a></li>
<li><a href="#" class="sitemap"><span></span></a></li>
<li><a href="#" class="search"><span></span></a></li>
</ul>
<h3 class="phone">
Тел. 8 (044) 561 66 22
</h3>
<div class="menu-wrap">
<jdoc:include type="modules" name="menu" style="none" />
</div>
<div class="why">
<h1>Преимущества работы с нами</h1>
<ul>
<li>1) Умеренные цены</li>
<li>2) Использование высококлассных материалов</li>
<li>3) Кротчайшие сроки выполнение работ</li>
<li>4) Лучший спектр услуг в городе</li>
<li>5) Гаранатия до 3х лет</li>
</ul>
</div>
</div>
<div class="content">
<?php if ($flag) {?>
<div class="scroller">
<h3>Наши работы</h3>
<div class="scroll">
<div class="scroll-visible">
<ul>
<jdoc:include type="modules" name="slider" style="none" />
</ul>
</div>
<a href="#" class="scroll-right"></a>
<a href="#" class="scroll-left"></a>
</div>
</div>
<div class="text-module">
<jdoc:include type="modules" name="main-text" style="none" />
</div>
<?php }else{?>
<jdoc:include type="component" />
<?php }?>
</div>
<div class="bottom-modules">
<div class="bottom-modules-item item-left"><jdoc:include type="modules" name="user1" style="xhtml" /></div>
<div class="bottom-modules-item item-right"><jdoc:include type="modules" name="user3" style="xhtml" /></div>
<div class="bottom-modules-item item-center"><jdoc:include type="modules" name="user2" style="xhtml" /></div>
</div>
<div class="footer-space"></div>
</div>
<div class="footer">
<span class="copyright">
© 2009<br />
Все права защищены
</span>
<span class="design"></span>
</div>
</body>
</html>
Areks,
19 Февраля 2010
-
+99.4
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
#include <iostream>
int *sfirst_function(void);
int *isecond_function(void);
int * sfirst_function(void)
{
int ilocal_to_first=11;
return &ilocal_to_first; // Возвращаем указатель на переменную, размещенную в стеке
}
int *isecond_function(void)
{
int ilocal_to_second=44;
return &ilocal_to_second; // ну и тут
}
void main()
{
int *pi=sfirst_function();
printf("First Function = %d\n",*pi);
int *si= isecond_function();
printf("Second Function = %d\n",*si);
}
Найдено на античате, в топике "помощь с лабораторными"
В этом конкретном примере, конечно, допустим возврат адреса локальной переменной, а вот в более крупном проекте автор столкнулся бы с нефиговой проблемой =)
RankoR,
18 Февраля 2010
-
+145.4
- 1
ViewState["Action"] = result.client == "merchantName" ? false : true;
nettrash,
18 Февраля 2010
-
+159.3
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
var res_html = "";
for (var i = 0; i < title_section.length; i++)
{
if (title_section[i].id == sel) {
res_html += '<div class="'+prefix+'section_title" onmouseover="section_sel(this,\''+ prefix +'\')" onmouseout="section_unsel(this,\''+ prefix +'\')"' +
'onclick="section_choise(this,'+'\''+url+'\'' + ')"' +
'id='+'"'+title_section[i].id+'" '
+'style='+'"font-weight: bold"'+'>'+
'<span class="'+ prefix +'dashed_anchor">' + title_section[i].name + '</span> ';
// res_html += '(' + number_section[i] + ')';
res_html += '</div>';
}
else{
res_html += '<div class="'+prefix+'section_title" onmouseover="section_sel(this,\''+ prefix +'\')" onmouseout="section_unsel(this,\''+ prefix +'\')"' +
'onclick="section_choise(this,'+'\''+url+'\'' + ')"' +
'id='+'"'+title_section[i].id+'" '
+'>'+
'<span class="'+ prefix +'dashed_anchor">' + title_section[i].name + '</span> ';
// res_html += '(' + number_section[i] + ')';
res_html += '</div>';
}
}
document.getElementById(prefix + "sections").innerHTML += res_html;
document.getElementById(prefix + "sections").innerHTML += '<a href='+'"?id=all"'+'><div class="'+prefix+'all_sections"><img src="media/img/01/arrow.jpg" alt=""/>' +
'<span style="color:black">Все разделы</span> </div></a>';
document.getElementById(prefix + "column_sections").style.width = (max_length + 7) + "ex";
/* document.getElementById(prefix + "green_sector").style.height = (document.getElementById(prefix + "column_other").offsetHeight - 14) + "px";*/
}
Яваскрипт от местного умельца:)
HollyGeek,
18 Февраля 2010
-
+167.8
- 1
date_in.date_ >= '".date("Y")."-".date("m")."-".date("d")."'
кусок SQL запроса...
Torch13,
18 Февраля 2010