C++ ξέχασα και αυτά που ήξερα

Συζητήσεις για γλώσσες προγραμματισμού και θέματα σχετικά με προγραμματισμό.
Post Reply
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

C++ ξέχασα και αυτά που ήξερα

Post by PaP » Wed May 05, 2004 5:43 pm

Βλέπετε κάποιο πρόβλημα στο παρακάτω;;;

Code: Select all

#ifndef _PANDORABOX_H_
#define _PANDORABOX_H

// Include an STL container needed by the Pandora program
#include <vector>

//Other includes needed
#include <iostream>
#include <fstream>
#include <string>
#include <math>

class PandoraBox{

	//Containers
	private:
		vector<char[]> vec;
		static int FibNums[];
		
	//Variables needed
		static int pass;
		static int passInc;
		static int parts;
		static bool generated;
		string password;
3 μεταγλωτιστές μου βγάζουν ότι δεν έχει δηλωθεί το string !!!
Borland, Visual Studio 6, GCC 3.3 3.2
User avatar
HdkiLLeR
Venus Project Founder
Venus Project Founder
Posts: 4356
Joined: Tue Jan 27, 2004 4:41 pm
Academic status: Alumnus/a
Gender:
Location: New York, NY
Contact:

Post by HdkiLLeR » Wed May 05, 2004 7:02 pm

Βασικά το έχεις σκίσει...

1)Δεν έχεις κλήσει το #ifndef.
2)Δεν έχεις δηλώσει ποιόν χώρο ονομασίας χρησιμοποιείς.
3)Vector<char[]> χλωμό σε κόβο...

Code: Select all

#ifndef _PANDORABOX_H_
#define _PANDORABOX_H

// Include an STL container needed by the Pandora program
#include <vector>

//Other includes needed
#include <iostream>
#include <fstream>
#include <string>
//#include <math>
using namespace std;

class PandoraBox{

   //Containers
   private:
      vector<char*> vec;
      static int FibNums[];

   //Variables needed
      static int pass;
      static int passInc;
      static int parts;
      static bool generated;
      string password;
};
#endif

είναι λογικότατο να μην βρίσκει τίποτα μιας και όλα αυτά βρίσκονται μέσα στο namespace std. Συνεπώς για να τα χρησιμοποιήσεις χωρίς δήλωση του namespace παραπάνω θα πρέπει να χρησιμοποιείς και τον τελεστή ανάλυσης εμβέλειας ::,πχ std::cout κλπ κλπ.

Τέλος το char[] η C++ το λαμβάνει σαν έναν δείκτη στην πρώτη θέση του πίνακα. Πχ char x[100]. To x δείχνει στην πρώτη θέση του πίνακα είναι το ίδιο με το char* point=&x[0]; Το point και το χ απο μόνα τους έχουν την ίδια τιμή για να καταλάβεις. Για να σου δουλέψει τώρα το vector θα πρέπει να του δώσεις έναν τύπο. Πχ vector<int>,vector<string>,vector<vector<int>>,vector<class1>,vector<set<class2>>...Γενικά κάτι που να αντιπροσοπεύει έναν τύπο. Το char[] δεν έιναι type οπότε θα σου χτυπήσει και εκεί.

Παραπάνω τα έχω διορθώσει όλα.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d-->--- s+:+ a- C++(+++) BILS++++$ P--- L++++>+++++ E--- W+++ N+ o+ K w--
O M+ V-- PS++>+++ PE- Y++ PGP++ t+ 5+ X+ R* tv b++ DI- D+ G+++ e+++>++++ h r++ y++
------END GEEK CODE BLOCK------

"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." -- Dennis Ritchie
User avatar
PaP
Venus Project Founder
Venus Project Founder
Posts: 1077
Joined: Wed Apr 21, 2004 12:06 am
Academic status: Alumnus/a
Location: San Francisco
Contact:

Ευτυχώς ξαναφόρτωσα το Module C++

Post by PaP » Wed May 05, 2004 9:24 pm

Thanx Bill. βασικά τα πρώτα λάθη τα βρήκα όλα και μείωσα σε από 55 λάθη σε 15 λεπτά αλλά αυτό με το char[] βοηθάει αρκετά. Thanx dude
Ωσονούπω γέννετο το Pandora Cipher Tool
User avatar
HdkiLLeR
Venus Project Founder
Venus Project Founder
Posts: 4356
Joined: Tue Jan 27, 2004 4:41 pm
Academic status: Alumnus/a
Gender:
Location: New York, NY
Contact:

Post by HdkiLLeR » Thu May 06, 2004 2:40 am

Αναμένω με αγωνία...Φτιάξε και ένα gui μιας και σε αυτά είσαι μέγιστος.

ΥΓ: θέλω credit στα σχόλια του code :)
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d-->--- s+:+ a- C++(+++) BILS++++$ P--- L++++>+++++ E--- W+++ N+ o+ K w--
O M+ V-- PS++>+++ PE- Y++ PGP++ t+ 5+ X+ R* tv b++ DI- D+ G+++ e+++>++++ h r++ y++
------END GEEK CODE BLOCK------

"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." -- Dennis Ritchie
Post Reply

Return to “Προγραμματισμός”