Computer Games Forum
 

Go Back   Computer Games Forum > Tech > The Workshop > Limbaje de programare

Notices

Căutare produse PC Garage: Şterge căutarea

Reply
 
LinkBack Thread Tools
Old 19-05-2006, 21:53   #1 (permalink)
Banned
 
Altair's Avatar
 
Join Date: Dec 2005
matrice cu STL

De ce nu merge asta? am incercat pe vreo 3 implementari de STL si face ca toti dracii, iese direct din program...

[CODE]
#include <vector>
#include <iostream>
using namespace std;

class ad
{
private:
vector<vector<int> > adj;
public:
ad(){adj.reserve(10); for (int i=0;i<10;i++) {adj[i].reserve(10);};};
void setadj(int x, int y) {adj[x][y]=1;};
void getadj (int x, int y) {cout<<adj[x][y];};
};

int main()
{
ad adi;
adi.setadj(1,4);
adi.getadj(1,4);
}[/CODE]
 
Altair is offline    Reply With Quote
Old 20-05-2006, 12:34   #2 (permalink)
Registered User
 
Dark's Avatar
 
Join Date: Nov 1999
Inlocuieste reserve() cu resize() in ambele locuri unde l-ai folosit. Cu reserve() nu se apeleaza constructorii pentru vectorii din interiorul lui adj, deci for-ul ala din constructorul lui ad foloseste obiecte neinitializate.
__________________
Scarbit de fapta ta cea rea
Degeaba plangi, acum, copile,
Ci du-te'n casa-acum si zi-le
Parintilor, isprava ta.
 
Dark is offline    Reply With Quote
Old 20-05-2006, 13:01   #3 (permalink)
Banned
 
Altair's Avatar
 
Join Date: Dec 2005
Ok, acum merge, thx
 
Altair is offline    Reply With Quote
Old 21-05-2006, 12:46   #4 (permalink)
BT
Registered User
 
BT's Avatar
 
Join Date: Jun 1999
Daca dimenisiunea este fixa, sunt indicate matrice normale, daca nu, e mai eficient sa folosesti un singur vector<int> pe care sa il tratezi ca o matrice avand in vedere ca ai functii de get si set.
 
BT is offline    Reply With Quote
Advertisment
Reply

  Computer Games Forum > Tech > The Workshop > Limbaje de programare

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 00:00.


Advertisement System V2.5 By   Branden
This site is copyrighted ©1997 - 2008, Computer Games Online SRL