IOT trap
Select messages from
# through # FAQ
[/[Print]\]

Forum@DeGiorgi -> Računalni sustavi na Fakultetu

#1: IOT trap Autor/ica: shokre PostPostano: 14:52 ned, 15. 1. 2006
    —
Radim neki program u C++-u (na studentu) u kojem koristim exceptione. Program se uspjesno kompajlira, ali kod pokretanja mi baca gresku:
Kod:
[student] [~/rp4] > g++ error.cpp -o error
[student] [~/rp4] > error
IOT trap
[student] [~/rp4] >


Evo i kod programa u kojem sam izolirao gresku:
Kod:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Greska {
  private:
  string text;

  public:
  Greska( const string &_text ) : text(_text) {};
  string GetText() const { return text; }
};

class Stupac {
  private:
  vector<string> podaci;

  public:
  void AddPodatak( const string );
  string GetPodatak( const vector<string>::size_type ) const;
};

void Stupac::AddPodatak( const string str ) {
  podaci.push_back( str );
}

string Stupac::GetPodatak( const vector<string>::size_type i ) const {
  if( i >= podaci.size() || i < 0 )
    throw new Greska( "Index out of bounds." );
  return podaci[i];
}

int main() {
  Stupac stupac;
  stupac.AddPodatak( "mirko" );
  stupac.AddPodatak( "fodor" );
  stupac.AddPodatak( "slavko" );
  stupac.AddPodatak( "zeljko" );

  try {
    cout << stupac.GetPodatak( 18 );
  }
  catch( Greska e ) {
    cerr << e.GetText() << endl;
  }

  return 0;
}


Jel mi moze netko pojasniti sto znaci ova greska i u cemu sam pogrijesio?

#2:  Autor/ica: shokre PostPostano: 14:57 ned, 15. 1. 2006
    —
Najdrazi su mi ovi problemi koji me zivciraju cijeli dan i onda kad postavim pitanje na forumu, onda mi postane jasno u cemu je problem Evil or Very Mad

Bacam "new Greska()" sto je tipa "Greska*", a hvatam "Greska".

Ako ce nekome ikada biti bitno - treba koristiti u parovima:
Kod:
throw new exception + catch exception*

ili

throw exception + catch exception



Forum@DeGiorgi -> Računalni sustavi na Fakultetu


output generated using printer-friendly topic mod. Vremenska zona: GMT + 01:00.

Stranica 1 / 1.

Powered by phpBB © 2001,2002 phpBB Group
Theme created by Vjacheslav Trushkin