Domino w C++ Obiektowo

0

Witajcie

Jestem laikiem w programowaniu ale mam zadanie napisac gre Domino w C++ obiektowo.

Problem moj polega na tym ze jezeli zrobie plik naglowkowy w ktorym jest napisana funkcja utworz_klocki() i w pliku main.cpp uzywam tej funkcji a nastepnie chce wykorzystac klocek np. zero_zero przy funkcji wypisz_dane_klocka() to wyskakuje mi blad ze klocek zero_zero nie jest zdefiniowany w tym pliku

 
#ifndef DOMINO_H
#define DOMINO_H

#include <iostream>

using namespace std;

class klocek
{
	private:
		int lewe_pole;
		int prawe_pole;
		int ustawienie; // ustawienie klocka np 2|3 lub 3|2 jezeli 1 to wieksza liczba po prawej
	public:
		
		void ustaw(int a, int b, int c)
		{
			lewe_pole=a;
			prawe_pole=b;
			ustawienie=c;
		}
		
		void wypisz_dane_klocka()
		{
			cout << "lewe pole to: " << lewe_pole << endl;
			cout << "prawe pole to: " <<  prawe_pole << endl; 
			cout << "ustawienie to: " << ustawienie << endl;
		}
		
};

#endif

 
#ifndef KLOCKI_H
#define KLOCKI_H

#include <iostream>
#include "domino.h"
using namespace std;


		
		void utworz_klocki()
			{
			// ------- klocki z zerem---------
			klocek zero_zero;
			zero_zero.ustaw(0, 0, 1);
			
			klocek zero_jeden;
			zero_jeden.ustaw(0, 1, 1);
			
			klocek zero_dwa;
			zero_dwa.ustaw(0, 2, 1);
			
			klocek zero_trzy;
			zero_trzy.ustaw(0, 3, 1);
			
			klocek zero_cztery;
			zero_cztery.ustaw(0, 4, 1);
			
			klocek zero_piec;
			zero_piec.ustaw(0, 5, 1);
			
			klocek zero_szesc;
			zero_szesc.ustaw(0, 6, 1);
			// ------- klocki z jedynka---------
			klocek jeden_jeden;
			jeden_jeden.ustaw(1, 1, 1);
			
			klocek jeden_dwa;
			jeden_dwa.ustaw(1, 2, 1);
			
			klocek jeden_trzy;
			jeden_trzy.ustaw(1, 3, 1);
			
			klocek jeden_cztery;
			jeden_cztery.ustaw(1, 4, 1);
			
			klocek jeden_piec;
			jeden_piec.ustaw(1, 5, 1);
			
			klocek jeden_szesc;
			jeden_szesc.ustaw(1, 6, 1);
			// ------- klocki z dwojka---------
			klocek dwa_dwa;
			dwa_dwa.ustaw(2, 2, 1);
			
			klocek dwa_trzy;
			dwa_trzy.ustaw(2, 3, 1);
			
			klocek dwa_cztery;
			dwa_cztery.ustaw(2, 4, 1);
			
			klocek dwa_piec;
			dwa_piec.ustaw(2, 5, 1);
			
			klocek dwa_szesc;
			dwa_szesc.ustaw(2, 6, 1);
			// ------- klocki z trojka---------
			klocek trzy_trzy;
			trzy_trzy.ustaw(3, 3, 1);
			
			klocek trzy_cztery;
			trzy_cztery.ustaw(3, 4, 1);
			
			klocek trzy_piec;
			trzy_piec.ustaw(3, 5, 1);
			
			klocek trzy_szesc;
			trzy_szesc.ustaw(3, 6, 1);
			// ------- klocki z czworka---------
			klocek cztery_cztery;
			cztery_cztery.ustaw(4, 4, 1);
			
			klocek cztery_piec;
			cztery_piec.ustaw(4, 5, 1);
			
			klocek cztery_szesc;
			cztery_szesc.ustaw(4, 6, 1);
			// ------- klocki z piatka---------
			klocek piec_piec;
			piec_piec.ustaw(5, 5, 1);
			
			klocek piec_szesc;
			piec_szesc.ustaw(5, 6, 1);
			// ------- klocki z szostka---------
			klocek szesc_szesc;
			szesc_szesc.ustaw(6, 6, 1);
			
			}

			

#endif

#include <iostream>
#include "menu.h"
#include "domino.h"
#include "klocki.h"
using namespace std;



int main()
{
	//menu a;
	
	//a.pierwsze();
	
	utworz_klocki();
	

	
	zero_zero.wypisz_dane_klocka():
}

 

prosze o pomoc w wyjasnieniu tego zjawiska jak i w rozwiazaniu i bardzo prosze o wyrozumialosc :)

2
  1. Jesteś niepoważny. A co jak będziesz miał planszę milion na milion elementów? To też tak to będziesz pisał? Lekcja na dziś: tablice, kontenery i pętle!
  2. To że masz jedną biedną klasę to nie znaczy że napisałeś coś obiektowo. Zrób sobie klasę Plansza w której będziesz miał tablicę z klockami i to w obiekcie tej klasy te klocki sobie utwórz. Ale błagam, tym razem z użyciem pętli!
  3. Następnie w main() tworzysz obiekt klasy Plansza i voila!
0

Dalej mam problem bo jak kompiluje to mam bledy tylko nie moge zlokalizowac bledu ;/

 
#include <iostream>
#include "menu.h"
#include "domino.h"
#include "plansza.h"
using namespace std;



int main()
{
	//menu a;
	
	//a.pierwsze();
	plansza a;
	a.dodaj_klocki;
	a.wypisz
	
}

#ifndef DOMINO_H
#define DOMINO_H

#include <iostream>

using namespace std;

class klocek
{
	private:
		int nazwa;
		int lewe_pole;
		int prawe_pole;
		int ustawienie; // ustawienie klocka np 2|3 lub 3|2 jezeli 1 to wieksza liczba po prawej
	public:
		
		klocek(int xnazwa, int xlewe_pole, int xprawe_pole, int xustawienie);
		
		void ustaw(int n, int a, int b, int c)
		{
			nazwa=n;
			lewe_pole=a;
			prawe_pole=b;
			ustawienie=c;
		}
		
		void wypisz_dane_klocka()
		{
			cout << "nazwa to: " << nazwa << endl;
			cout << "lewe pole to: " << lewe_pole << endl;
			cout << "prawe pole to: " <<  prawe_pole << endl; 
			cout << "ustawienie to: " << ustawienie << endl;
		}
		
};

#endif

 
#ifndef PLANSZA_H
#define PLANSZA_H

#include <iostream>
#include <vector>
#include "domino.h"
using namespace std;


class plansza : public klocek
{
	private:
	
	public:
	
	//array klocki[28];
	
	vector < klocek > wszystkie_klocki;
	
	void dodaj_klocki
	{
		for(int i=0; i <= 27; i++)
		{
			n=i;
			for( int a = 0; a <= 6; a++)
			{
				z=a;
				for(int b=0; b <= 6; b++)
				{
					x=b;
					c=1;
				}
			}
			wszystkie_klocki.push_back(klocek(n, z, x, c));
		}
		klocek::klocek(int xnazwa, int xlewe_pole, int xprawe_pole, int xustawienie);
	: n(xnazwa)
	, z(xlewe_pole)
	, x(xprawe_pole)
	, c(xustawieni)
	}
	
	void wypisz
	{
		for( int i=0; i < wszystkie_klocki.size(); i++)
		{
			cout ,, wszystkie_klocki[i] << endl;
		}
	}


}



		


#endif

 

komunikaty bledow:

 
g++ -Wall -o "main" "main.cpp" (in directory: /home/wujekstyle/PO/projekt2)
In file included from main.cpp:4:0:
plansza.h:41:2: error: variable or field ‘dodaj_klocki’ declared void
plansza.h:41:2: error: expected ‘;’ at end of member declaration
plansza.h:49:2: error: variable or field ‘wypisz’ declared void
plansza.h:49:2: error: expected ‘;’ at end of member declaration
plansza.h:52:1: error: expected ‘;’ after class definition
plansza.h: In constructor ‘plansza::plansza()’:
plansza.h:10:7: error: no matching function for call to ‘klocek::klocek()’
plansza.h:10:7: note: candidates are:
In file included from main.cpp:3:0:
domino.h:17:3: note: klocek::klocek(int, int, int, int)
domino.h:17:3: note:   candidate expects 4 arguments, 0 provided
domino.h:8:7: note: klocek::klocek(const klocek&)
domino.h:8:7: note:   candidate expects 1 argument, 0 provided
main.cpp: In function ‘int main()’:
main.cpp:14:10: note: synthesized method ‘plansza::plansza()’ first required here
main.cpp:15:4: error: ‘class plansza’ has no member named ‘dodaj_klocki’
main.cpp:16:4: error: ‘class plansza’ has no member named ‘wypisz’
main.cpp:18:1: error: expected ‘;’ before ‘}’ token
Compilation failed.
1

Plansza nie powinna pochodzić od klocek.

0

po usunieciu

 : public klocek

zostaja takie bledy

 g++ -Wall -o "main" "main.cpp" (in directory: /home/wujekstyle/PO/projekt2)
In file included from main.cpp:4:0:
plansza.h:41:2: error: variable or field ‘dodaj_klocki’ declared void
plansza.h:49:2: error: variable or field ‘wypisz’ declared void
main.cpp: In function ‘int main()’:
main.cpp:15:4: error: ‘class plansza’ has no member named ‘dodaj_klocki’
main.cpp:16:4: error: ‘class plansza’ has no member named ‘wypisz’
Compilation failed.
1

void dodaj_klocki() - to samo z wypisz().
Konstruktor Klocki jest w dziwnym miejscu.
A tak a propos, głowa mi strasznie nawala i nie mam siły nad czymś poważnym się zastanowić więc duperele robię:

#include <iostream>
using namespace std;
 
// ewentualnie do plansza.h
class Plansza
  {
   public:
   class Klocek
     {
      static const char Code[][2];
      char Nr;
      bool turn;
      public:
      Klocek(char Nr=0):Nr(Nr),turn(false) {}
      operator bool()const { return turn; }
      bool Turn()const { return turn; }
      void Turn(bool turn) { this->turn=turn; }
      void Swap() { turn=!turn; }
      char Lewy()const { return Code[(int)Nr][0^turn]; }
      char Prawy()const { return Code[(int)Nr][1^turn]; }
      ostream &prn(ostream &s)const { return s<<'|'<<Lewy()<<':'<<Prawy()<<'|'; }
     };
   private:
   unsigned rozmiar;
   Klocek *Klocki;
   public:
   Plansza(unsigned komplet=1);
   ~Plansza() { if(rozmiar) delete[] Klocki; }
   operator unsigned()const { return rozmiar; }
   const Klocek &operator[](unsigned i)const { return Klocki[i]; }
   Klocek &operator[](unsigned i) { return Klocki[i]; }
   ostream &prn(ostream &s)const;
  };
 
ostream &operator<<(ostream &s,const Plansza::Klocek &K) { return K.prn(s); } 
ostream &operator<<(ostream &s,const Plansza &P) { return P.prn(s); } 
 
//ewentualnie do plansza.cpp (dołączyć "plansza.h" , <iostream> oraz using namespace std)
const char Plansza::Klocek::Code[][2]=
  {
   {'0','0'},{'0','1'},{'0','2'},{'0','3'},{'0','4'},{'0','5'},{'0','6'},
   {'1','1'},{'1','2'},{'1','3'},{'1','4'},{'1','5'},{'1','6'},
   {'2','2'},{'2','3'},{'2','4'},{'2','5'},{'2','6'},
   {'3','3'},{'3','4'},{'3','5'},{'3','6'},
   {'4','4'},{'4','5'},{'4','6'},
   {'5','5'},{'5','6'},
   {'6','6'}
  };
 
Plansza::Plansza(unsigned komplet):rozmiar(komplet*27),Klocki(rozmiar?new Klocek[rozmiar]:0)
  {
   for(unsigned i=0;i<rozmiar;++i) Klocki[i]=(char)(i%27); // konstruktor + operator=
  }
 
ostream &Plansza::prn(ostream &s)const
  {
   for(unsigned i=0;i<rozmiar;++i) s<<("-"+!i)<<Klocki[i];
   return s;
  }
 
// ewentualnie do main.cpp (dołączyć "plansza.h")
int main()
  {
   Plansza P;
   cout<<P<<endl;
   P[1].Turn(true);
   cout<<P<<endl;
   P[2].Turn(true);
   cout<<P<<endl;
   cin.sync(); cin.get();
   return 0;
  }

Czy nie jest wygodniejsze użycie? Pisano na sucho bez kompilatora więc mogą być drobne usterki.

EDIT1 // dodane wskazówki podziału.
EDIT2 // wyeliminowano ostrzeżenia.
EDIT3 // mała optymalizacja.

0

przy podmianie mojego kodu na twoj wyrzuca takie bledy:

g++ -Wall -o "main" "main.cpp" (in directory: /home/wujekstyle/PO/projekt2)
In file included from main.cpp:4:0:
plansza.h: In constructor ‘Plansza::Klocek::Klocek(char)’:
plansza.h:17:12: warning: ‘Plansza::Klocek::Nr’ will be initialized after [-Wreorder]
plansza.h:16:12: warning:   ‘bool Plansza::Klocek::turn’ [-Wreorder]
plansza.h:19:7: warning:   when initialized here [-Wreorder]
plansza.h: In member function ‘char Plansza::Klocek::Lewy() const’:
plansza.h:24:44: warning: array subscript has type ‘char’ [-Wchar-subscripts]
plansza.h: In member function ‘char Plansza::Klocek::Prawy() const’:
plansza.h:25:45: warning: array subscript has type ‘char’ [-Wchar-subscripts]
plansza.h: At global scope:
plansza.h:66:1: error: ‘cout’ does not name a type
plansza.h:67:1: error: ‘P’ does not name a type
plansza.h:68:1: error: ‘cout’ does not name a type
plansza.h:69:1: error: ‘P’ does not name a type
plansza.h:70:1: error: ‘cout’ does not name a type
Compilation failed.
 
#ifndef PLANSZA_H
#define PLANSZA_H

#include <iostream>
#include <vector>

using namespace std;


class Plansza
  {
   public:
   class Klocek
     {
      static const char Code[][2];
      bool turn;
      char Nr;
      public:
      Klocek(char Nr=0):Nr(Nr),turn(false) {}
      operator bool()const { return turn; }
      bool Turn()const { return turn; }
      void Turn(bool turn) { this->turn=turn; }
      void Swap() { turn=!turn; }
      char Lewy()const { return '0'+Code[Nr][0^turn]; }
      char Prawy()const { return '0'+Code[Nr][1^turn]; }
      ostream &prn(ostream &s)const { return s<<'|'<<Lewy()<<':'<<Prawy()<<'|'; }
     };
   private:
   unsigned rozmiar;
   Klocek *Klocki;
   public:
   Plansza(unsigned komplet=1);
   ~Plansza() { if(rozmiar) delete[] Klocki; }
   operator unsigned()const { return rozmiar; }
   const Klocek &operator[](unsigned i)const { return Klocki[i]; }
   Klocek &operator[](unsigned i) { return Klocki[i]; }
   ostream &prn(ostream &s)const;
  };
 
const char Plansza::Klocek::Code[][2]=
  {
   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},
   {1,1},{1,2},{1,3},{1,4},{1,5},{1,6},
   {2,2},{2,3},{2,4},{2,5},{2,6},
   {3,3},{3,4},{3,5},{3,6},
   {4,4},{4,5},{4,6},
   {5,5},{5,6},
   {6,6}
  };
 
ostream &operator<<(ostream &s,const Plansza::Klocek &K) { return K.prn(s); } 
ostream &operator<<(ostream &s,const Plansza &P) { return P.prn(s); } 
 
Plansza::Plansza(unsigned komplet):rozmiar(komplet*27),Klocki(rozmiar?new Klocek[rozmiar]:0)
  {
   for(unsigned i=0;i<rozmiar;++i) Klocki[i]=(char)(i%27); // konstruktor + operator=
  }
 
ostream &Plansza::prn(ostream &s)const
  {
   for(unsigned i=0;i<rozmiar;++i) s<<("-"+!i)<<Klocki[i];
   return s;
  }
 
Plansza P;
cout<<P<<endl;
P[1].Turn(true);
cout<<P<<endl;
P[2].Turn(true);
cout<<P<<endl;



		


#endif
 
0

To co na samym dole (instrukcje testujące) wpakuj do main.
Konstruktor Planszy i metodę prn przenieś do cpp deklarację Code też do cpp

0
_13th_Dragon napisał(a):

\Konstruktor Planszy i metodę prn przenieś do cpp deklarację Code też do cpp

do jakiego cpp ? zrobic oddzielne cpp w ktorym jest to co napisales i zaincludowac w nim plansza.h ?

na razie mam tak:
mani.cpp

 #include <iostream>
#include "menu.h"

#include "plansza.h"
#include <vector>
using namespace std;



int main()
{
	//menu a;
	
	//a.pierwsze();
	
Plansza P;
cout<<P<<endl;
P[1].Turn(true);
cout<<P<<endl;
P[2].Turn(true);
cout<<P<<endl;
}

plansza.h

 #ifndef PLANSZA_H
#define PLANSZA_H

#include <iostream>
#include <vector>

using namespace std;


class Plansza
  {
   public:
   
   class Klocek
     {
      static const char Code[][2];
      bool turn;
      char Nr;
      
      public:
      
      Klocek(char Nr=0):Nr(Nr),turn(false) {}
      operator bool()const { return turn; }
      bool Turn()const { return turn; }
      void Turn(bool turn) { this->turn=turn; }
      void Swap() { turn=!turn; }
      char Lewy()const { return '0'+Code[Nr][0^turn]; }
      char Prawy()const { return '0'+Code[Nr][1^turn]; }
      ostream &prn(ostream &s)const { return s<<'|'<<Lewy()<<':'<<Prawy()<<'|'; }
     };
     
   private:
   unsigned rozmiar;
   Klocek *Klocki;
   public:
   Plansza(unsigned komplet=1);
   ~Plansza() { if(rozmiar) delete[] Klocki; }
   operator unsigned()const { return rozmiar; }
   const Klocek &operator[](unsigned i)const { return Klocki[i]; }
   Klocek &operator[](unsigned i) { return Klocki[i]; }
   ostream &prn(ostream &s)const;
  };
 
const char Plansza::Klocek::Code[][2]=
  {
   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},
   {1,1},{1,2},{1,3},{1,4},{1,5},{1,6},
   {2,2},{2,3},{2,4},{2,5},{2,6},
   {3,3},{3,4},{3,5},{3,6},
   {4,4},{4,5},{4,6},
   {5,5},{5,6},
   {6,6}
  };
 
ostream &operator<<(ostream &s,const Plansza::Klocek &K) { return K.prn(s); } ;
ostream &operator<<(ostream &s,const Plansza &P) { return P.prn(s); } ;

#endif

plansza.cpp

 #include <iostream>
#include "menu.h"
#include "plansza.h"
#include <vector>
using namespace std;



int main()
{
Plansza::Plansza(unsigned komplet):rozmiar(komplet*27),Klocki(rozmiar?new Klocek[rozmiar]:0)
  {
   for(unsigned i=0;i<rozmiar;++i) Klocki[i]=(char)(i%27); // konstruktor + operator=
  }
 
ostream &Plansza::prn(ostream &s)const
  {
   for(unsigned i=0;i<rozmiar;++i) s<<("-"+!i)<<Klocki[i];
   return s;
  }
}
0

To:

const char Plansza::Klocek::Code[][2]=
  {
   {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},
   {1,1},{1,2},{1,3},{1,4},{1,5},{1,6},
   {2,2},{2,3},{2,4},{2,5},{2,6},
   {3,3},{3,4},{3,5},{3,6},
   {4,4},{4,5},{4,6},
   {5,5},{5,6},
   {6,6}
  };

przenieś do plansza.cpp
#include <vector> - nie potrzebujesz.
Wywal main z plansza.cpp ale metody zostaw.
Tak genieralnie dla początkujących odradzam dzielenia programu na kilka plików źródłowych, tym bardziej że początkujące nigdy nie piszą tak skomplikowanych projektów które naprawdę potrzebowali by takiego podziału.

0

zostaj te bledy

g++ -Wall -o "plansza" "plansza.cpp" (in directory: /home/wujekstyle/PO/projekt2)
In file included from plansza.cpp:3:0:
plansza.h: In constructor ‘Plansza::Klocek::Klocek(char)’:
plansza.h:18:12: warning: ‘Plansza::Klocek::Nr’ will be initialized after [-Wreorder]
plansza.h:17:12: warning:   ‘bool Plansza::Klocek::turn’ [-Wreorder]
plansza.h:22:7: warning:   when initialized here [-Wreorder]
plansza.h: In member function ‘char Plansza::Klocek::Lewy() const’:
plansza.h:27:44: warning: array subscript has type ‘char’ [-Wchar-subscripts]
plansza.h: In member function ‘char Plansza::Klocek::Prawy() const’:
plansza.h:28:45: warning: array subscript has type ‘char’ [-Wchar-subscripts]
Compilation failed.
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
 
0

To tylko ostrzeżenia, które warto wyeliminować lecz nie koniecznie.
Weź całość jak podałem wklej do plansza.cpp
albo użyj jakiegoś IDE
albo naucz się kompilować programy składające się z kilku źródeł: g++ -o "domino" "plansza.cpp" "main.cpp"

0

Dobra jednak wracam do kolekcji bo chyba latwiej mi to ogarnac.... ale i tak mam problem jestem na tym etapie:
PLANSZA.H

#ifndef PLANSZA_H
#define PLANSZA_H

#include <iostream>
#include "domino.h"
#include <vector>
using namespace std;

class plansza
{
	private:
	
	public:
	vector < klocek > wszystkie_klocki;
	
	 void dodaj_klocki()
        {
                for(int i=0; i <= 27; i++)
                {
                        int n=i;
                        for( int a = 0; a <= 6; a++)
                        {
                                int z=a;
                                for(int b=0; b <= 6; b++)
                                {
                                        int x=b;
                                        int c=1;
                                }
                        }
                        wszystkie_klocki.push_back(klocek(int n, int z, int x, int c));
                }

		};
		
		void wypisz()
        {
                for( int i=0; i < wszystkie_klocki.size(); i++)
                {
                        cout << wszystkie_klocki[i] << endl;
                }
        };
};
		


#endif

 

DOMINO.H

#ifndef DOMINO_H
#define DOMINO_H
 
#include <iostream>
 
using namespace std;
 
class klocek
{
        private:
                int lewe_pole;
                int prawe_pole;
                int ustawienie; // ustawienie klocka np 2|3 lub 3|2 jezeli 1 to wieksza liczba po prawej
        public:
 
				klocek(int lp, int pp, int ust);
				
                void ustaw(int a, int b, int c)
                {
                        lewe_pole=a;
                        prawe_pole=b;
                        ustawienie=c;
                }
 
                void wypisz_dane_klocka()
                {
                        cout << "lewe pole to: " << lewe_pole << endl;
                        cout << "prawe pole to: " <<  prawe_pole << endl; 
                        cout << "ustawienie to: " << ustawienie << endl;
                }
 
};
 
#endif
 

i main.cpp

#include <iostream>
#include "menu.h"
#include "klocki.h"
#include "plansza.h"
#include <vector>
using namespace std;



int main()
{
//menu a;
//a.pierwsze();
//menu a;
//a.pierwsze();

}
 

a mam takie bledy

g++ -Wall -o "main" "main.cpp" (in directory: /home/wujekstyle/PO/projekt2)
In file included from main.cpp:4:0:
plansza.h: In member function ‘void plansza::dodaj_klocki()’:
plansza.h:26:45: warning: unused variable ‘x’ [-Wunused-variable]
plansza.h:27:45: warning: unused variable ‘c’ [-Wunused-variable]
plansza.h:23:37: warning: unused variable ‘z’ [-Wunused-variable]
plansza.h:30:58: error: expected primary-expression before ‘(’ token
plansza.h:30:59: error: expected primary-expression before ‘int’
plansza.h:30:66: error: expected primary-expression before ‘int’
plansza.h:30:73: error: expected primary-expression before ‘int’
plansza.h:30:80: error: expected primary-expression before ‘int’
plansza.h:20:29: warning: unused variable ‘n’ [-Wunused-variable]
plansza.h: In member function ‘void plansza::wypisz()’:
plansza.h:37:57: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
plansza.h:39:51: error: no match for ‘operator<<’ in ‘std::cout << ((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’
plansza.h:39:51: note: candidates are:
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:106:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:106:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:115:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:115:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:125:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:125:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:164:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:164:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘long int’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:168:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:168:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘long unsigned int’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:172:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:172:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘bool’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:607:0,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:93:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:93:5: note:   no known conversion for argument 1 from ‘klocek’ to ‘short int’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:179:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:179:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘short unsigned int’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:607:0,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:107:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:107:5: note:   no known conversion for argument 1 from ‘klocek’ to ‘int’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:190:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:190:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘unsigned int’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:199:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:199:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘long long int’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:203:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:203:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘long long unsigned int’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:218:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:218:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘double’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:222:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:222:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘float’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:230:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:230:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘long double’
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:243:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:243:7: note:   no known conversion for argument 1 from ‘klocek’ to ‘const void*’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:607:0,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:121:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:121:5: note:   no known conversion for argument 1 from ‘klocek’ to ‘std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/string:54:0,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h:42,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h:43,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ios:43,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:40,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:2750:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h:2750:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   ‘klocek’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:469:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:469:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘klocek’)
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:474:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:474:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘char’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:480:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:480:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘char’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:486:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:486:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘signed char’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:491:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:491:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘unsigned char’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:511:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:511:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   mismatched types ‘const _CharT*’ and ‘klocek’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:607:0,
                 from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:323:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc:323:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘const char*’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:528:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:528:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘const char*’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:541:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:541:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘const signed char*’
In file included from /usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream:40:0,
                 from main.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:546:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
/usr/lib/gcc/i686-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream:546:5: note:   template argument deduction/substitution failed:
In file included from main.cpp:4:0:
plansza.h:39:51: note:   cannot convert ‘((plansza*)this)->plansza::wszystkie_klocki.std::vector<_Tp, _Alloc>::operator[]<klocek, std::allocator<klocek> >(((std::vector<klocek>::size_type)i))’ (type ‘klocek’) to type ‘const unsigned char*’
Compilation failed.
 
2

Ano widzę, łatwiej.

0
  1. nie powinno sie uzywac "using namespace ..." w plikach naglowkowych
  2. void dodaj_klocki()
    {
    ....
    }; <- ???
  3. void wypisz()
    {
    ....
    }; <- ???
for(int i=0; i <= 27; i++)
                {
                        int n=i;
                        for( int a = 0; a <= 6; a++)
                        {
                                int z=a;
                                for(int b=0; b <= 6; b++)
                                {
                                        int x=b;
                                        int c=1;
                                }
                        }
	   }

to jest jeden wielki wtf.

wszystkie_klocki.push_back(klocek(int n, int z, int x, int c));

j/w
6.

cout << wszystkie_klocki[i] << endl;

a gdzie przeciazony operator<< dla klocka?
7. klocek(int lp, int pp, int ust); definicja tego jest w oddzielnym pliku, tak ?

0

Tak wiec poczynilem nastepujace postepy:

 
// main.cpp

#include <iostream>
#include <vector>
#include "klocek.h"
#include "plansza.h"
using namespace std;


int main()
{
plansza a;
a.dodaj_klocki();
a.wypisz();
}
 
//klocek.h
#ifndef KLOCEK_H
#define KLOCEK_H
 
#include <iostream>

class klocek
{
        private:
                int lewe_pole;
                int prawe_pole;
                int ustawienie; // ustawienie klocka np 2|3 lub 3|2 jezeli 1 to wieksza liczba po prawej
        public:		
                void ustaw(int a, int b, int c)
                {
                        lewe_pole=a;
                        prawe_pole=b;
                        ustawienie=c;
                }
 
                void wypisz_dane_klocka()
                {
                        std::cout << "lewe pole to: " << lewe_pole << std::endl;
                        std::cout << "prawe pole to: " <<  prawe_pole << std::endl; 
                        std::cout << "ustawienie to: " << ustawienie << std::endl;
                }
                
                klocek(int lp, int pp, int ust) {
					lewe_pole=lp;
					prawe_pole=pp;
					ustawienie=ust;
					}
				friend std::ostream & operator<< (std::ostream &wyjscie, const klocek &s);
				
 
};

std::ostream & operator<< (std::ostream &wyjscie, const klocek &s)
{
	return wyjscie << "lewe pole: " <<s.lewe_pole << std::endl << "prawe pole: " << s.prawe_pole << std::endl << "ustawienie to: " << s.ustawienie << std::endl;
}

#endif

//plansza.h

#ifndef PLANSZA_H
#define PLANSZA_H

#include "klocek.h"
#include <vector>

class plansza
{
	private:
	
	public:
	std::vector < klocek > wszystkie_klocki;
	
	 void dodaj_klocki()
        {
             for(int i=0; i < 7; i++)
             {
				 for(int j=6; j >= 7; j--)
				 
				 wszystkie_klocki.push_back( klocek(i, j, 1));
			 }

		}
		
		void wypisz()
        {
             for( int i=0; i < wszystkie_klocki.size(); i++)
                {
                        std::cout << wszystkie_klocki[i] << std::endl;
                }
        }
};

#endif

 

wszystko sie kompiluje tyle ze jak odpale program to nic nie wyswietla a chyba powinien....

1

Nie powinno, bo nic nie dodajesz: for(int j=6; j >= 7; j--) ta pętla nigdy nie wykona żadnego kroku.
Zacznij porządnie formatować kod, staraj się używać ++x zamiast x++ tam gdzie jest to możliwe.

0

for(int j=6; j >= 7; j--) zmienielm na for(int j=6; j >= 0; j--) i dziala wyswietla wszystkie klocki

0

Działa? A nie za dużo ich wyświetla?

0

tak za duzo to zauwazylem ale musze po prostu dac ifa jeszcze przed wywolaniem wszystkie_klocki.push_back....

1
for(int i=0;i<7;++i) for(int j=i;j<7;++j) wszystkie_klocki.push_back( klocek(i,j,1)); // równiutko 28
0
 #include <iostream>
// main.cpp

#include <vector>
#include "klocek.h"
#include "plansza.h"
#include "gracz.h"
#include <ctime>
#include <unistd.h>
#include "gra.h"
using namespace std;



int main()
{
plansza worek;
worek.dodaj_klocki();
gracz pierwszy;
gracz drugi;
gra gramy;
plansza stol;


// ---- losowanie 7 roznych klockow

srand( time( NULL ) );

for(int i=0; i<7; i++)
{	
	int a;
	a = worek.losuj_klocek();
	pierwszy.dodaj_klocek(worek.klocki_w_worku[a]);
	worek.klocki_w_worku.erase( worek.klocki_w_worku.begin() + a);
}
// ---- koniec losowania-

for(int i=0; i<7; i++)
{	
	int a;
	a = worek.losuj_klocek();
	drugi.dodaj_klocek(worek.klocki_w_worku[a]);
	worek.klocki_w_worku.erase( worek.klocki_w_worku.begin() + a);
}
cout << "Zaczyna gracz pierwszy" << endl;





while(1)
{
	if(pierwszy.ruch=1)
	{
	cout << "Klocki gracza 1" << endl;
	pierwszy.wypisz();
	cout << endl;
	cout << "Podaj numer klocka ktory chcesz polozyc liczac od 0" << endl;
	int x;
	cin >> x;
	stol.dodaj_klocek(pierwszy.klocki_gracza[x]);
	stol.wypisz();
	pierwszy.klocki_gracza.erase(pierwszy.klocki_gracza.begin()+x);
	cout << endl;
	pierwszy.zakoncz_ruch();
	drugi.ruch=1;
	}
	else
	{
	cout << "Klocki gracza 2" << endl;
	drugi.wypisz();
	cout << endl;
	cout << "Podaj numer klocka ktory chcesz polozyc liczac od 0" << endl;
	int x;
	cin >> x;
	stol.dodaj_klocek(drugi.klocki_gracza[x]);
	drugi.klocki_gracza.erase(drugi.klocki_gracza.begin()+x);
	stol.wypisz();
	cout << endl;
	drugi.zakoncz_ruch();
	pierwszy.ruch=1;
	}
}




}


// klocek.h
#ifndef KLOCEK_H
#define KLOCEK_H
 
#include <iostream>

class klocek
{
        private:
                int lewe_pole;
                int prawe_pole;
                int ustawienie; // ustawienie klocka np 2|3 lub 3|2 jezeli 1 to wieksza liczba po prawej
        public:		
                void ustaw(int a, int b, int c)
                {
                        lewe_pole=a;
                        prawe_pole=b;
                        ustawienie=c;
                }
 
                void wypisz_dane_klocka()
                {
                        std::cout << "lewe pole to: " << lewe_pole << std::endl;
                        std::cout << "prawe pole to: " <<  prawe_pole << std::endl; 
                        std::cout << "ustawienie to: " << ustawienie << std::endl;
                }
                
                void obroc_klocek()
				{
					int a;
					a=lewe_pole;
					lewe_pole=prawe_pole;
					prawe_pole=a;
				}
                
                klocek(int lp, int pp, int ust) {
					lewe_pole=lp;
					prawe_pole=pp;
					ustawienie=ust;
					}
				friend std::ostream & operator<< (std::ostream &wyjscie, const klocek &s);
				
 
};

std::ostream & operator<< (std::ostream &wyjscie, const klocek &s)
{
	return wyjscie << "|" <<s.lewe_pole << "|" << s.prawe_pole << "|";
}

#endif

 
// plansza.h
#ifndef PLANSZA_H
#define PLANSZA_H

#include "klocek.h"
#include <vector>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <time.h>//<ctime>

class plansza
{
	private:
	
	public:
	std::vector < klocek > klocki_w_worku;
	
		void dodaj_klocki()
        {
             for(int i=0; i < 7; ++i)
             {
				 for(int j=i; j<7; ++j)
				 
				 klocki_w_worku.push_back( klocek(i, j, 1));
			 }

		}
		
		void dodaj_klocek(klocek a)
        {	 
				 klocki_w_worku.push_back(a);
		}
		
		void wypisz()
        {
             for( int i=0; i < klocki_w_worku.size(); i++)
                {
				
                        std::cout << klocki_w_worku[i];
                }
        }
        
        int losuj_klocek()
		{
			
		int i;
		i = rand() % klocki_w_worku.size();
		return i;
		}
};

#endif
 
 
// gracz.h
#ifndef GRACZ_H
#define GRACZ_H

#include "klocek.h"
#include <vector>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <ctime>

class gracz
{
	private:
	
	public:
	std::vector < klocek > klocki_gracza;
	int punkty;
	int ruch;
	int mozliwy_ruch;
	std::string nazwa;
	
	void dodaj_klocek(klocek a)
		{
			klocki_gracza.push_back(a);
			
		}
		
	void wypisz()
        {
             for( int i=0; i < klocki_gracza.size(); i++)
                {
				
                        std::cout << klocki_gracza[i];
                }
        }
        
	void zakoncz_ruch()
{
	ruch=0;
}
	
};

#endif

Problem polega na tym ze jak to odpale to funkcja if(pierwszy.ruch=1) zawsze jest prawdziwa a wedlug mnie nie powinno tak byc...

0

if(pierwszy.ruch == 1) o to Ci chyba chodzilo.

1 użytkowników online, w tym zalogowanych: 0, gości: 1