Domino w C++ Obiektowo

Domino w C++ Obiektowo
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
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

Kopiuj
 
#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

Kopiuj
 
#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

Kopiuj
#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 :)

edytowany 2x, ostatnio: wujekstyle
Shalom
  • Rejestracja:około 21 lat
  • Ostatnio:prawie 3 lata
  • Lokalizacja:Space: the final frontier
  • Postów:26433
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!

"Nie brookliński most, ale przemienić w jasny, nowy dzień najsmutniejszą noc - to jest dopiero coś!"
edytowany 1x, ostatnio: Shalom
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

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

Kopiuj
 
#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
	
}

Kopiuj
#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

 
Kopiuj
#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:

Kopiuj
 
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.
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
1

Plansza nie powinna pochodzić od klocek.


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

po usunieciu

Kopiuj
 : public klocek

zostaja takie bledy

Kopiuj
 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.
edytowany 2x, ostatnio: wujekstyle
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
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ę:

Kopiuj
#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.


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
edytowany 3x, ostatnio: _13th_Dragon
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

przy podmianie mojego kodu na twoj wyrzuca takie bledy:

Kopiuj
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.
 
Kopiuj
#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
 
edytowany 1x, ostatnio: wujekstyle
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
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


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
edytowany 1x, ostatnio: _13th_Dragon
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
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

Kopiuj
 #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

Kopiuj
 #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

Kopiuj
 #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;
  }
}
edytowany 1x, ostatnio: wujekstyle
_13th_Dragon
Poprawiłem post, albo wpisujesz całość do jednego pliku albo dzielisz zgodnie ze wskazówkami w komentarzach.
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
0

To:

Kopiuj
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.


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
edytowany 2x, ostatnio: _13th_Dragon
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

zostaj te bledy

Kopiuj
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
 
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
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"


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

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

Kopiuj
#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

Kopiuj
#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

Kopiuj
#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

Kopiuj
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.
 
edytowany 1x, ostatnio: wujekstyle
n0name_l
Skad czerpiesz wiedze dot. programowania czy skladni tego jezyka ? O.o
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
2

Ano widzę, łatwiej.


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
n0name_l
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 4 lata
  • Postów:2412
0
  1. nie powinno sie uzywac "using namespace ..." w plikach naglowkowych
  2. void dodaj_klocki()
    {
    ....
    }; <- ???
  3. void wypisz()
    {
    ....
    }; <- ???
Kopiuj
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.

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

j/w
6.

Kopiuj
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 ?

Zobacz pozostały 1 komentarz
WU
nie czekam na gotowca tylko chce to zrozumiec... a rady sa zbyt skomplikowane ;/
WU
co do podpunktu 7 to chyba jest konstruktor ;)
_13th_Dragon
No jasne, rada - "dla początkujących pisać w jednym pliku cpp" - to tak skomplikowana rada że nie ma co.
WU
2 i3 usuniete ";"
n0name_l
Wypunktowalem Ci te bledy, ktore zauwazylem _13th_Dragon wspomnial o kompilacji to moze laskawie otworzysz jakas dokumentacje, kurs, ksiazke cokolwiek i przeanalizujesz to samemu, a nie po 30 sekundach odpisujesz, ze chcesz to zrozumiec. Jakbys chcial to bys juz to dawno mial zrobione... Co do 7. przy probie stworzenia obiektu z takim konstruktorem kompilator zglosi protest najpewniej o tresci undefined reference.
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

Tak wiec poczynilem nastepujace postepy:

Kopiuj
 
// main.cpp

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


int main()
{
plansza a;
a.dodaj_klocki();
a.wypisz();
}
Kopiuj
 
//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

Kopiuj
//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....

WU
jest jedynie warning: g++ -Wall -o "main" "main.cpp" (in directory: /home/wujekstyle/PO/projekt3) In file included from main.cpp:4:0: plansza.h: In member function ‘void plansza::wypisz()’: plansza.h:27:54: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Compilation finished successfully.
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
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.


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

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

n0name_l
Taka mala rada, ze wzgledu na to, ze kod sie czesciej czyta niz pisze to nie uzywaj zadnych magicznych liczb tylko porob stale. "warning: comparison between signed and unsigned integer expressions", a to wystepuje dlatego, ze vector<T>.size() zwraca wartosci size_t, a Ty ja porownujesz do inta.
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
0

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


Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0

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

edytowany 1x, ostatnio: wujekstyle
_13th_Dragon
  • Rejestracja:ponad 19 lat
  • Ostatnio:3 miesiące
1
Kopiuj
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

Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.
edytowany 1x, ostatnio: _13th_Dragon
WU
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 12 lat
  • Postów:11
0
Kopiuj
 #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;
	}
}




}


Kopiuj
// 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

 
Kopiuj
// 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
 
Kopiuj
 
// 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...

n0name_l
  • Rejestracja:ponad 12 lat
  • Ostatnio:ponad 4 lata
  • Postów:2412
0

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

Kliknij, aby dodać treść...

Pomoc 1.18.8

Typografia

Edytor obsługuje składnie Markdown, w której pojedynczy akcent *kursywa* oraz _kursywa_ to pochylenie. Z kolei podwójny akcent **pogrubienie** oraz __pogrubienie__ to pogrubienie. Dodanie znaczników ~~strike~~ to przekreślenie.

Możesz dodać formatowanie komendami , , oraz .

Ponieważ dekoracja podkreślenia jest przeznaczona na linki, markdown nie zawiera specjalnej składni dla podkreślenia. Dlatego by dodać podkreślenie, użyj <u>underline</u>.

Komendy formatujące reagują na skróty klawiszowe: Ctrl+B, Ctrl+I, Ctrl+U oraz Ctrl+S.

Linki

By dodać link w edytorze użyj komendy lub użyj składni [title](link). URL umieszczony w linku lub nawet URL umieszczony bezpośrednio w tekście będzie aktywny i klikalny.

Jeżeli chcesz, możesz samodzielnie dodać link: <a href="link">title</a>.

Wewnętrzne odnośniki

Możesz umieścić odnośnik do wewnętrznej podstrony, używając następującej składni: [[Delphi/Kompendium]] lub [[Delphi/Kompendium|kliknij, aby przejść do kompendium]]. Odnośniki mogą prowadzić do Forum 4programmers.net lub np. do Kompendium.

Wspomnienia użytkowników

By wspomnieć użytkownika forum, wpisz w formularzu znak @. Zobaczysz okienko samouzupełniające nazwy użytkowników. Samouzupełnienie dobierze odpowiedni format wspomnienia, zależnie od tego czy w nazwie użytkownika znajduje się spacja.

Znaczniki HTML

Dozwolone jest używanie niektórych znaczników HTML: <a>, <b>, <i>, <kbd>, <del>, <strong>, <dfn>, <pre>, <blockquote>, <hr/>, <sub>, <sup> oraz <img/>.

Skróty klawiszowe

Dodaj kombinację klawiszy komendą notacji klawiszy lub skrótem klawiszowym Alt+K.

Reprezentuj kombinacje klawiszowe używając taga <kbd>. Oddziel od siebie klawisze znakiem plus, np <kbd>Alt+Tab</kbd>.

Indeks górny oraz dolny

Przykład: wpisując H<sub>2</sub>O i m<sup>2</sup> otrzymasz: H2O i m2.

Składnia Tex

By precyzyjnie wyrazić działanie matematyczne, użyj składni Tex.

<tex>arcctg(x) = argtan(\frac{1}{x}) = arcsin(\frac{1}{\sqrt{1+x^2}})</tex>

Kod źródłowy

Krótkie fragmenty kodu

Wszelkie jednolinijkowe instrukcje języka programowania powinny być zawarte pomiędzy obróconymi apostrofami: `kod instrukcji` lub ``console.log(`string`);``.

Kod wielolinijkowy

Dodaj fragment kodu komendą . Fragmenty kodu zajmujące całą lub więcej linijek powinny być umieszczone w wielolinijkowym fragmencie kodu. Znaczniki ``` lub ~~~ umożliwiają kolorowanie różnych języków programowania. Możemy nadać nazwę języka programowania używając auto-uzupełnienia, kod został pokolorowany używając konkretnych ustawień kolorowania składni:

```javascript
document.write('Hello World');
```

Możesz zaznaczyć również już wklejony kod w edytorze, i użyć komendy  by zamienić go w kod. Użyj kombinacji Ctrl+`, by dodać fragment kodu bez oznaczników języka.

Tabelki

Dodaj przykładową tabelkę używając komendy . Przykładowa tabelka składa się z dwóch kolumn, nagłówka i jednego wiersza.

Wygeneruj tabelkę na podstawie szablonu. Oddziel komórki separatorem ; lub |, a następnie zaznacz szablonu.

nazwisko;dziedzina;odkrycie
Pitagoras;mathematics;Pythagorean Theorem
Albert Einstein;physics;General Relativity
Marie Curie, Pierre Curie;chemistry;Radium, Polonium

Użyj komendy by zamienić zaznaczony szablon na tabelkę Markdown.

Lista uporządkowana i nieuporządkowana

Możliwe jest tworzenie listy numerowanych oraz wypunktowanych. Wystarczy, że pierwszym znakiem linii będzie * lub - dla listy nieuporządkowanej oraz 1. dla listy uporządkowanej.

Użyj komendy by dodać listę uporządkowaną.

1. Lista numerowana
2. Lista numerowana

Użyj komendy by dodać listę nieuporządkowaną.

* Lista wypunktowana
* Lista wypunktowana
** Lista wypunktowana (drugi poziom)

Składnia Markdown

Edytor obsługuje składnię Markdown, która składa się ze znaków specjalnych. Dostępne komendy, jak formatowanie , dodanie tabelki lub fragmentu kodu są w pewnym sensie świadome otaczającej jej składni, i postarają się unikać uszkodzenia jej.

Dla przykładu, używając tylko dostępnych komend, nie możemy dodać formatowania pogrubienia do kodu wielolinijkowego, albo dodać listy do tabelki - mogłoby to doprowadzić do uszkodzenia składni.

W pewnych odosobnionych przypadkach brak nowej linii przed elementami markdown również mógłby uszkodzić składnie, dlatego edytor dodaje brakujące nowe linie. Dla przykładu, dodanie formatowania pochylenia zaraz po tabelce, mogłoby zostać błędne zinterpretowane, więc edytor doda oddzielającą nową linię pomiędzy tabelką, a pochyleniem.

Skróty klawiszowe

Skróty formatujące, kiedy w edytorze znajduje się pojedynczy kursor, wstawiają sformatowany tekst przykładowy. Jeśli w edytorze znajduje się zaznaczenie (słowo, linijka, paragraf), wtedy zaznaczenie zostaje sformatowane.

  • Ctrl+B - dodaj pogrubienie lub pogrub zaznaczenie
  • Ctrl+I - dodaj pochylenie lub pochyl zaznaczenie
  • Ctrl+U - dodaj podkreślenie lub podkreśl zaznaczenie
  • Ctrl+S - dodaj przekreślenie lub przekreśl zaznaczenie

Notacja Klawiszy

  • Alt+K - dodaj notację klawiszy

Fragment kodu bez oznacznika

  • Alt+C - dodaj pusty fragment kodu

Skróty operujące na kodzie i linijkach:

  • Alt+L - zaznaczenie całej linii
  • Alt+, Alt+ - przeniesienie linijki w której znajduje się kursor w górę/dół.
  • Tab/⌘+] - dodaj wcięcie (wcięcie w prawo)
  • Shit+Tab/⌘+[ - usunięcie wcięcia (wycięcie w lewo)

Dodawanie postów:

  • Ctrl+Enter - dodaj post
  • ⌘+Enter - dodaj post (MacOS)