dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Debug Error!

 
dev.gamez.lv Forum Index -> Programmēšana
View previous topic :: View next topic  
Author Message
Janka



Joined: 14 Nov 2005
Posts: 19
Location: Jelgava

PostPosted: Thu Nov 17, 2005 7:08 pm    Post subject: Debug Error!

Kaads, paliidiet luudzu!
Quote:

Microsoft Visual C++ Debug Library
Debug Error!
Program: d:\Visualstudio\testing\strings\debug\strings.exe

HEAP CORRUPTION DETECTED: after Normal block (#114) at 0x00355BC8
CRT detected that the application wrote to memory after end of heap buffer.

(Press Retry to debug the application)
Abort Retry Ignore


izlec shaadaa vietaa:
Code:

      delete [] old;


type* old = str (= "Hello!\0")

Quote:

template{
type = char
}


Last edited by Janka on Thu Nov 17, 2005 7:50 pm; edited 1 time in total
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Thu Nov 17, 2005 7:23 pm    Post subject:

Kas ir str()?
Kāpēc tur ir vienādības zīme aiz ( ?
Ko nozīmē tavs "template { type=char }" ?
Back to top
View user's profile Send e-mail
Janka



Joined: 14 Nov 2005
Posts: 19
Location: Jelgava

PostPosted: Thu Nov 17, 2005 7:41 pm    Post subject:

type* str;

aiz ( = tap'ec, ka es nor'adu kas tas ir) nu kaut kaa taa, laikam vajadzeeja iekavu vietaa lietot /* un */

type ir template, kas ir char - nu kaut kaa taa...
Back to top
View user's profile Send e-mail
Vecais_Dumais_Laacis
Guru
Guru


Joined: 29 Jan 2004
Posts: 800

PostPosted: Thu Nov 17, 2005 7:58 pm    Post subject:

po moimu tev old ir pointeris uz konstantu stringu tb tu nevari vinju dzeest
_________________
...un ja bites buutu laachi...
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Thu Nov 17, 2005 9:43 pm    Post subject:

Joprojām nesaprotu to str() funkciju un = zīmi aiz ( iekavas.
Back to top
View user's profile Send e-mail
Janka



Joined: 14 Nov 2005
Posts: 19
Location: Jelgava

PostPosted: Fri Nov 18, 2005 12:25 am    Post subject:

ok, pierakstiishsu veelreiz...
type* old = str (= "Hello!\0") == type* old = str /* = "Hello\0" */
Ceru, ka tagad saprati Smile piekriitu nebiju uzrakstiijis pareizi Rolling Eyes
Quote:

po moimu tev old ir pointeris uz konstantu stringu tb tu nevari vinju dzeest


Nu nav uz konstantu, to jau es arii iedomaajos, ja kaads vareetu pateikt kur, vareetu ielikt netaa lai var apluukot...
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Fri Nov 18, 2005 12:48 am    Post subject:

Ah nu beidzot sapratu. Tas str ir kautkāds cits mainīgais! Tak vajag uzreiz normāli rakstīt..!

A kā tu šamam piešķir vērtību, parādīsi?
Ta kautvai paste.php.lv ieliec (tikai dieva dēļ, nevis visu, bet fragmentu tikai!), vai ja nav garš kods, tad te pat [code] bbtagos.
Back to top
View user's profile Send e-mail
Janka



Joined: 14 Nov 2005
Posts: 19
Location: Jelgava

PostPosted: Fri Nov 18, 2005 12:18 pm    Post subject:

nav jau garsh (kaa nekaa tikai tests): Laughing
Code:

#pragma once

template<class type>
class STRING{
private:
   type*   data;
   int      used, allocated;
public:
   STRING():used(1),allocated(1),data(0){
      data = new type[1];
      data[0] = '\0';}

   // a STRING from string
   STRING(type* str):used(0),allocated(0),data(0){
      if(!str) return;
      // get size of string
      int lenght = 0;
      const type* p = str;
      while(*p){
         p++;
         lenght++;}
      used = allocated = lenght+1;
      data = new type[used];
      for(int i=0;i<used;i++)   data[i]=str[i];
      data[used]='\0';}

   // pieliidzinaashanas operators
   void operator=(const type* str)   {
      if(!str) return;
      // get size of string
      int lenght = 0;
      const type* p = str;
      while(*p){
         p++;
         lenght++;}
      used = allocated = lenght+1;
      data = new type[used];
      for(int i=0;i<used;i++) data[i]=str[i];
      data[used]='\0';
   }

   // construct string from other string
   STRING(const STRING<type>& other):used(0),allocated(0),data(0){
      *this = other;}

   // destructor
   ~STRING(){
      delete[] data;} // shitaa vieta arii karaas

   // return string
   type* c_str(){   return data;   }
   
   // return size
   int size(){ return used-1; }
   
   // append a char
   void append(type ch){
      if(used+1>allocated)   reallocate(used+1);
      data[used-1]=ch; data[used]='\0';
      used+=1;
   }

   // append a string
   void append(type* str)   {
      if(!str) return;
      // a size of string
      int lenght=0;
      const type* p = str;
      while(*p){
         p++;
         lenght++;}
      if(used+lenght>allocated) reallocate(used+lenght);
      for(int i=0;i<lenght;i++) data[used+i]=str[i];
      used = used+lenght;
      data[used-1]='\0';
   }

   type operator[](int index) {
      if(index<0||index>=used) return;
      return data[index];
   }

private:
   void reallocate(int new_size){
      if(new_size==allocated) // no need to reallocate memory
         return;

      type* old = data;
      
      data = new type[new_size];
      allocated = new_size;

      int lenght = used < new_size ? used : new_size;
      for(int i=0;i<lenght;i++) data[i]=old[i];
      data[lenght]='\0';
      if(used>allocated) used = allocated;

      delete [] old;
   }
};

typedef STRING<char> stringc;

#include <stdlib.h>
#include <iostream>

using namespace std;

int main(){
   stringc str;
   str = "Hollo!!!\n";
   
   cout<<str.c_str();
   
   str.append('A');
   str.append("ste\n");

   stringc s;
   s = "K-kas";
   str.append(s.c_str());
   str.append('\n');
   cout<<str.c_str();
   system("PAUSE");
   return 0;
}
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Fri Nov 18, 2005 3:19 pm    Post subject:

A kas notiek, ja izvāc cout'us? Tad arī tas pats?

Un kas vainas STL string klasei, ka negribi to izmantot?
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> Programmēšana All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group