Problem z kompliacją w Dev C++

0

Witam

To jest mój pierwszy wątek mam nadzieje że nie ostatni. Potrzebuję pomocy. Mam program napisany w C++.
Program działa prawidłowo ale pod linuxem po pewnych poprawkach Potrzebuje tego programu w Dev C++. Próbowałem go prezkształcić ale wywala trochę błędów. Bede wdzięczny za pomoc. Pewnie to błachostka lecz nie mam już pomysłu. Pozdrawiam

Kod :

#include <iostream>
#include <cstdlib>

//#ifndef _image_h_
//#define _image_h_

using namespace std;

typedef unsigned char byte;

class Image
{
private:
   byte **tab;																//tablica przechowująca wartości pikseli obrazu
   int width;
   int height;
   //void alloc(int width, int height);										//utworzenie tablicy
   void dealloc();															//zniszczenie tablicy
public:
   Image();																	//konstruktor
   Image(int width, int height);											//konstruktor
   Image(const Image& image);												//konstruktor kopiujący
   Image(const Image& image, int x, int y, int w, int h);					//konstruktor kopiujący
   ~Image();																//destruktor
   Image& operator=(const Image& image);									//operator przypisania
   int getWidth() const;													//zwraca width
   int getHeight() const;													//zwraca height
   void assignFrom(const Image& image, int x, int y, int w, int h); 		//kopiuje zawartość innego obrazka
   byte getPixel(int x, int y); 											//zwraca wartość (kolor) piksela na pozycji [x, y]
   void putPixel(int x, int y, byte value);                                 //zapis piksela
   void fillInImage(byte value);											//nadaje ten sam kolor wszystkim pikselom
   void print(); 															//wyświetlenie obrazka
}

//#endif



   
   
   
   void Image::alloc(int width, int height)																	//utworzenie tablicy
        {
			this->width = width;
            this->height = height;
			tab = new byte*[width];
            for (int i=0; i<width; ++i)
            tab[i] = new byte[height];
        }
   void Image::dealloc()																					//zniszczenie tablicy
        {
            for(int i=0; i<width; ++i)
            delete [] tab[i];
            delete [] tab;
        }
   Image::Image()																							//konstruktor
		{
			alloc(0, 0);
			cout<<" Konstruktor zostal wywolany \n\n";
		}
   Image::Image(int width, int height)																		//konstruktor
		{
			alloc(width, height);
			cout<<" Konstruktor zostal wywolany \n\n";
		}
   Image::Image(const Image& image)																			//konstruktor kopiujący
		{
			alloc(0, 0);
			*this = image;
			cout<<" Konstruktor kopiujacy zostal wywolany \n\n";
		}
   Image::Image(const Image& image, int x, int y, int w, int h)												//konstruktor kopiujący
		{
			alloc(0, 0);
			assignFrom(image, x, y, w, h);
			cout<<" Konstruktor kopiujacy zostal wywolany \n\n";
		}
   Image::~Image()																							//destruktor
		{
			dealloc();
			cout<<" Destruktor zostal wywolany \n\n";
		}
   void Image::operator=(const Image& image)																//operator przypisania
		{
			assignFrom(image, 0, 0, image.getWidth(), image.getHeight());
		}
   int Image::getWidth() const																				//zwraca width
		{
			return width;
		}
   int Image::getHeight() const																				//zwraca height
		{
			return height;
		}
   void Image::assignFrom(const Image& image, int x, int y, int w, int h) 									//kopiuje zawartość innego obrazka
		{
			dealloc();
			alloc(w, h);
			for (int i=0; i<w; ++i)
				{
					for (int j=0; j<h; ++j)
						{
							tab[i][j]=int(image.tab[x+i][y+j]);
						}
				}			
		}
   byte Image::getPixel(int x, int y) 																		//zwraca wartość (kolor) piksela na pozycji [x, y]
		{
			if(x>width || y>height)
				{
					cout<<"Blad! Podane indeksy wykraczaja poza obszar obrazu.";
					cout<<"Wpisz indeksy maksymalnie do ["<<getWidth()<<"]["<<getHeight()<<"].";
				}
			else
				return tab[x][y];
		}
   void Image::putPixel(int x, int y, byte value)                                                           //zapis piksela
        {
            if(x>width || y>height)
				{
					cout<<"Blad! Podane indeksy wykraczaja poza obszar obrazu.";
					cout<<"Wpisz indeksy maksymalnie do ["<<getWidth()<<"]["<<getHeight()<<"].";
				}
            else
                tab[x][y] = value;
        }
   void Image::fillInImage(byte value)																		//nadaje ten sam kolor wszystkim pikselom
		{
			for (int i=0; i<width; i++)
				{
					for(int j = 0; j<height; j++)
						{
							tab[i][j] = value;
						}
				}
		}
   void Image::print() 																					    //wyświetlenie obrazka
		{
			for (int i=0; i<width; i++)
				{
					for(int j = 0; j<height; j++)
						{
							if(tab[i][j]<=100)
							cout<<"X";
							else
							cout<<" ";
						}
				}
		}


int main()
{
	cout<<"Zostanie stworzony obiekt obraz1.";
	Image obraz1(2,2);
	
	cout<<"Width = "<<obraz1.getWidth();
	cout<<"Height = "<<obraz1.getHeight();
	system("PAUSE");
	
	cout<<endl<<"Teraz dokona sie zapis pikseli"<<endl;
	obraz1.putPixel(0, 0, 50);
	obraz1.putPixel(0, 1, 120);
	obraz1.putPixel(1, 0, 99);
	obraz1.putPixel(1, 1, 200);
	
	cout<<endl<<"Piksel na pozycji [3,3] ma wartosc: "<<obraz1.getPixel(3,3)<<endl;
	cout<<endl<<"Piksel na pozycji [0,0] ma wartosc: "<<obraz1.getPixel(0,0)<<endl;
	system("PAUSE");
	
	cout<<endl<<"Wyswietlimy obraz1."<<endl;
	obraz1.print();
	system("PAUSE");
	
	cout<<"Stworzymy obiekt obraz2 identyczny jak obraz1."<<endl;
	Image obraz2(obraz1);
	
	cout<<"Width = "<<obraz1.getWidth();
	cout<<"Height = "<<obraz1.getHeight();
	system("PAUSE");

	cout<<endl<<"Wyswietlimy obraz2."<<endl;
	obraz2.print();
	system("PAUSE");
	
	cout<<endl<<"Nadamy ta sama jasnosc pikselom obiektu obraz2."<<endl;
	obraz2.fillInImage(0);
	system("PAUSE");
	
	cout<<endl<<"A teraz ponownie wyswietlimy obraz2."<<endl;
	obraz2.print();
	
	cout<<"\n\n\n";
	system("PAUSE");
	return 0;
}
0

Jakie błędy wywala??

0

Podaję Log z kompilacji :

Kompilator: Default compiler
Building Makefile: "C:\Users\MSI\Desktop\Makefile.win"
Wykonywanie make...
make.exe -f "C:\Users\MSI\Desktop\Makefile.win" all
g++.exe -c cw/main.cpp -o cw/main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

cw/main.cpp error: new types may not be defined in a return type

cw/main.cpp error: two or more data types in declaration of alloc' cw/main.cpp:46: error: no Image Image::alloc(int, int)' member function declared in class `Image'

cw/main.cpp: In constructor Image::Image()': cw/main.cpp:61: error: alloc' undeclared (first use this function)
cw/main.cpp error: (Each undeclared identifier is reported only once for each function it appears in.)

cw/main.cpp: In constructor Image::Image(int, int)': cw/main.cpp:66: error: alloc' undeclared (first use this function)
cw/main.cpp: In copy constructor Image::Image(const Image&)': cw/main.cpp:71: error: alloc' undeclared (first use this function)
cw/main.cpp: In constructor `Image::Image(const Image&, int, int, int, int)':

cw/main.cpp error: alloc' undeclared (first use this function) cw/main.cpp: At global scope: cw/main.cpp:87: error: prototype for void Image::operator=(const Image&)' does not match any in class `Image'
cw/main.cpp error: candidate is: Image& Image::operator=(const Image&)

cw/main.cpp error: void Image::operator=(const Image&)' and Image& Image::operator=(const Image&)' cannot be overloaded
cw/main.cpp: In member function void Image::assignFrom(const Image&, int, int, int, int)': cw/main.cpp:101: error: alloc' undeclared (first use this function)

make.exe: *** [cw/main.o] Error 1

Wykonanie zakończone

0

alloc jest zakomentowane

0

Ok dzięki to właściwie sam zrobiłem ( wstawiłem komentarz) i nie usunąłem. Problemy nadal są proszę o pomoc:

Kompilator: Default compiler
Building Makefile: "C:\Users\MSI\Desktop\Makefile.win"
Wykonywanie make...
make.exe -f "C:\Users\MSI\Desktop\Makefile.win" all
g++.exe -c cw/main.cpp -o cw/main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

cw/main.cpp error: new types may not be defined in a return type

cw/main.cpp error: two or more data types in declaration of alloc' cw/main.cpp:46: error: prototype for Image Image::alloc(int, int)' does not match any in class Image' cw/main.cpp:20: error: candidate is: void Image::alloc(int, int) cw/main.cpp:46: error: Image Image::alloc(int, int)' and `void Image::alloc(int, int)' cannot be overloaded

cw/main.cpp error: prototype for void Image::operator=(const Image&)' does not match any in class Image'

cw/main.cpp error: candidate is: Image& Image::operator=(const Image&)
cw/main.cpp error: void Image::operator=(const Image&)' and Image& Image::operator=(const Image&)' cannot be overloaded

make.exe: *** [cw/main.o] Error 1

Wykonanie zakończone

0
#include <iostream>
#include <cstdlib>

//#ifndef _image_h_
//#define _image_h_

using namespace std;

typedef unsigned char byte;

class Image
{
    private:
   byte **tab;                                                                                                                                //tablica przechowująca wartości pikseli obrazu
   int width;
   int height;
   void alloc(int width, int height);                                                                                //utworzenie tablicy
   void dealloc();                                                                                                                        //zniszczenie tablicy
    public:
   Image();                                                                                                                                        //konstruktor
   Image(int width, int height);                                                                                        //konstruktor
   Image(const Image& image);                                                                                                //konstruktor kopiujący
   Image(const Image& image, int x, int y, int w, int h);                                        //konstruktor kopiujący
   ~Image();                                                                                                                                //destruktor
   Image& operator=(const Image& image);                                                                        //operator przypisania
   int getWidth() const;                                                                                                        //zwraca width
   int getHeight() const;                                                                                                        //zwraca height
   void assignFrom(const Image& image, int x, int y, int w, int h);                 //kopiuje zawartość innego obrazka
   byte getPixel(int x, int y);                                                                                         //zwraca wartość (kolor) piksela na pozycji [x, y]
   void putPixel(int x, int y, byte value);                                 //zapis piksela
   void fillInImage(byte value);                                                                                        //nadaje ten sam kolor wszystkim pikselom
   void print();                                                                                                                         //wyświetlenie obrazka
};

//#endif



   
   
   
   void Image::alloc(int width, int height)                                                                                                                                        //utworzenie tablicy
{
                        this->width = width;
            this->height = height;
                        tab = new byte*[width];
            for (int i=0; i<width; ++i)
            tab[i] = new byte[height];
}
   void Image::dealloc()                                                                                                                                                                        //zniszczenie tablicy
{
            for(int i=0; i<width; ++i)
            delete [] tab[i];
            delete [] tab;
}
   Image::Image()                                                                                                                                                                                        //konstruktor
{
                        alloc(0, 0);
                        cout<<" Konstruktor zostal wywolany \n\n";
}
   Image::Image(int width, int height)                                                                                                                                                //konstruktor
{
                        alloc(width, height);
                        cout<<" Konstruktor zostal wywolany \n\n";
}
   Image::Image(const Image& image)                                                                                                                                                        //konstruktor kopiujący
{
                        alloc(0, 0);
                        *this = image;
                        cout<<" Konstruktor kopiujacy zostal wywolany \n\n";
}
   Image::Image(const Image& image, int x, int y, int w, int h)                                                                                                //konstruktor kopiujący
{
                        alloc(0, 0);
                        assignFrom(image, x, y, w, h);
                        cout<<" Konstruktor kopiujacy zostal wywolany \n\n";
}
   Image::~Image()                                                                                                                                                                                        //destruktor
{
                        dealloc();
                        cout<<" Destruktor zostal wywolany \n\n";
}
   Image& Image::operator=(const Image& image)                                                                                                                                //operator przypisania
{
                        assignFrom(image, 0, 0, image.getWidth(), image.getHeight());
}
   int Image::getWidth() const                                                                                                                                                                //zwraca width
{
                        return width;
}
   int Image::getHeight() const                                                                                                                                                                //zwraca height
{
                        return height;
}
   void Image::assignFrom(const Image& image, int x, int y, int w, int h)                                                                         //kopiuje zawartość innego obrazka
{
                        dealloc();
                        alloc(w, h);
                        for (int i=0; i<w; ++i)
{
                                        for (int j=0; j<h; ++j)
{
                                                        tab[i][j]=int(image.tab[x+i][y+j]);
}
}                       
}
   byte Image::getPixel(int x, int y)                                                                                                                                                 //zwraca wartość (kolor) piksela na pozycji [x, y]
{
                        if(x>width || y>height)
{
                                        cout<<"Blad! Podane indeksy wykraczaja poza obszar obrazu.";
                                        cout<<"Wpisz indeksy maksymalnie do ["<<getWidth()<<"]["<<getHeight()<<"].";
}
                        else
                                return tab[x][y];
}
   void Image::putPixel(int x, int y, byte value)                                                           //zapis piksela
{
            if(x>width || y>height)
{
                                        cout<<"Blad! Podane indeksy wykraczaja poza obszar obrazu.";
                                        cout<<"Wpisz indeksy maksymalnie do ["<<getWidth()<<"]["<<getHeight()<<"].";
}
            else
                tab[x][y] = value;
}
   void Image::fillInImage(byte value)                                                                                                                                                //nadaje ten sam kolor wszystkim pikselom
{
                        for (int i=0; i<width; i++)
{
                                        for(int j = 0; j<height; j++)
{
                                                        tab[i][j] = value;
}
}
}
   void Image::print()                                                                                                                                                                             //wyświetlenie obrazka
{
                        for (int i=0; i<width; i++)
{
                                        for(int j = 0; j<height; j++)
{
                                                        if(tab[i][j]<=100)
                                                        cout<<"X";
                                                        else
                                                        cout<<" ";
}
}
}


int main()
{
        cout<<"Zostanie stworzony obiekt obraz1.";
        Image obraz1(2,2);
       
        cout<<"Width = "<<obraz1.getWidth();
        cout<<"Height = "<<obraz1.getHeight();
        system("PAUSE");
       
        cout<<endl<<"Teraz dokona sie zapis pikseli"<<endl;
        obraz1.putPixel(0, 0, 50);
        obraz1.putPixel(0, 1, 120);
        obraz1.putPixel(1, 0, 99);
        obraz1.putPixel(1, 1, 200);
       
        cout<<endl<<"Piksel na pozycji [3,3] ma wartosc: "<<obraz1.getPixel(3,3)<<endl;
        cout<<endl<<"Piksel na pozycji [0,0] ma wartosc: "<<obraz1.getPixel(0,0)<<endl;
        system("PAUSE");
       
        cout<<endl<<"Wyswietlimy obraz1."<<endl;
        obraz1.print();
        system("PAUSE");
       
        cout<<"Stworzymy obiekt obraz2 identyczny jak obraz1."<<endl;
        Image obraz2(obraz1);
       
        cout<<"Width = "<<obraz1.getWidth();
        cout<<"Height = "<<obraz1.getHeight();
        system("PAUSE");

        cout<<endl<<"Wyswietlimy obraz2."<<endl;
        obraz2.print();
        system("PAUSE");
       
        cout<<endl<<"Nadamy ta sama jasnosc pikselom obiektu obraz2."<<endl;
        obraz2.fillInImage(0);
        system("PAUSE");
       
        cout<<endl<<"A teraz ponownie wyswietlimy obraz2."<<endl;
        obraz2.print();
       
        cout<<"\n\n\n";
        system("PAUSE");
        return 0;
}

Tutaj masz poprawione. Się kompiluje, ale nie uruchamiałem programu :-)
Brakowało ';' po definicji class, zakomentowane alloc, przy implementacji operatora= był błąd (zwracany był typ void).

0

Dzięki za pomoc . Wszystko działa.
Temat zamknięty.

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