
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[216.73.216.60] |
![]() |
|
Сообщ.
#1
,
|
|
|
Здраствуйте, уважаемые гуру
![]() Уповаю на вашу помошь в следующем вопросе. Есть прога, допустим picture.ccp и в ней заголовок инклудится picture.h В файле заголовка описанны функции класса. Вот привожу пример: picture.cpp ![]() ![]() #include "picture.h" void Picture::name_of_fnct(void) { int q, tabsize; Byte *bp; NumColors = numcolors ? (1 << BitsNeeded(numcolors)) : 0; BitsPrPrimColor = colorres; .......... [дальше идут функции описанные в файле заглловке и т.д. Всего строк с 1000] .......... } picture.h ![]() ![]() #if !defined(__PICTURE_H) #define __PICTURE_H #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #define fntNORMAL 0 #define fntBOLD 1 #define fntSCRIPT 2 typedef unsigned Word; /* At least two bytes (16 bits) */ typedef unsigned char Byte; /* Exactly one byte (8 bits) */ typedef struct { Word LocalScreenWidth, LocalScreenHeight; Byte GlobalColorTableSize : 3, SortFlag : 1, ColorResolution : 3, GlobalColorTableFlag : 1; Byte BackgroundColorIndex; Byte PixelAspectRatio; } ScreenDescriptor; typedef struct { Byte Separator; Word LeftPosition, TopPosition; Word Width, Height; Byte LocalColorTableSize : 3, Reserved : 2, SortFlag : 1, InterlaceFlag : 1, LocalColorTableFlag : 1; } ImageDescriptor; typedef struct { Byte Separator; Byte Label; Byte BlockSize; Byte Reserved : 3, Disposal : 3, UserInput : 1, Transparent : 1; Word DelayTime; Byte TransparentColor; Byte Terminator; } ControlDescriptor; class Picture { public: Picture(); Picture(int,int,int,int); // width, height, #colors, #bits/color component ~Picture(); Picture(char*); void PutPixel(int x,int y,int col) { if(y>=0 && y<(int)leny && x>=0 && x<(int)lenx && col<NumColors) pic[y][x]=col; }; void PrintCharUp(int,int,int,char c); // x,y,color,char void PrintChar(int,int,int,char c); // x,y,color,char void PrintString(int,int,int,char* s); // x,y,color,string void PrintStringUp(int,int,int,char* s); // x,y,color,string void Bar(int,int,int,int,int); // x1,y1,x2,y2,color void Line(int,int,int,int,int); // x1,y1,x2,y2,color void Circle(int,int,int,int); // x1,y1,r,color void FilledCircle(int,int,int,int); // x1,y1,r,color int GetPixel(int x,int y) { if(y>=0 && y<(int)leny && x>=0 && x<(int)lenx) return pic[y][x]; else return 0; }; void SetColor(int colornum, int red, int green, int blue); void SetTransparent(int colornum) { TransparentColor=colornum; }; void SetFont(int); // fnt????? SaveAsGIF(FILE* f); private: unsigned char** pic; Word lenx,leny; int usefont; /* GIF Routines */ int BitsPrPrimColor, /* Bits pr primary color */ NumColors; /* Number of colors in color table */ Byte *ColorTable; int TransparentColor; Word RelPixX, RelPixY; /* Used by InputByte() -function */ FILE* OutFile; Byte Buffer[256]; /* There must be one to much !!! */ int Index, /* Current byte in buffer */ BitsLeft; /* Bits left to fill in current byte. These are right-justified */ Byte *StrChr; Word *StrNxt,*StrHsh,NumStrings; void InitGIF(int,int); int AllocStrtab(void); void FreeStrtab(void); int WriteBits(int bits, int numbits); Word FindCharString(Word index, Byte b); Word AddCharString(Word index, Byte b); void ClearStrtab(int codesize); int ResetOutBitFile(void); int Write(void *buf, unsigned len); int WriteScreenDescriptor(ScreenDescriptor *sd); int WriteControlDescriptor(ControlDescriptor *cd); int WriteImageDescriptor(ImageDescriptor *id); int WriteWord(Word w); int WriteByte(Byte b); int BitsNeeded(Word n); int InputByte(void); int LZWCompress(int codesize); }; #endif Компилим. Пишет "Error E2141 picture.h 56: Declaration syntax error". Компилю на Borland C++ 5.5.1 for Win32. Результат аналогичный везде. Указывает на ошибку ровно в строке 56 : class Picture. Странно. Синтаксисс соблюдён. Обьсните. Что это. Иначе я сойду с ума ) |
Сообщ.
#2
,
|
|
|
знаешь - это конечно в все хорошо и класс большой
но вот я что-то не нашел метод name_of_fnct в .h файле ![]() уж не по этому ли ![]() Больше в голову ничего не приходит - проверил у себя - ошибок нет Возникла пара сомнений, но и они не оправдались 1 сомнение: 56 строка это ![]() ![]() void PutPixel(int x,int y,int col) { if(y>=0 && y<(int)leny && x>=0 && x<(int)lenx && col<NumColors) pic[y][x]=col; }; скажи, а компилятор поймет что ты используешь массив pic, если он у тебя ниже описан? 2 сомнение: там же ![]() ![]() void PutPixel(int x,int y,int col) { if(y>=0 && y<(int)leny && x>=0 && x<(int)lenx && col<NumColors) pic[y][x]=col; } ; - лишняя ни 1 ни 2 сомнения не подтвердились - хотя может это дело компилятора - у меня Visual C++ 7.1 И еще компилятор ругнулся warning'ом на метод SaveAsGIF(FILE* f); это же у тебя не конструктор, ты бы ему значение поставил для возвращения |
Сообщ.
#3
,
|
|
|
name_of_function -- это я к примеру. Там такого нету. Там ещё и др. файлы подсоединяются. Проблема исключительно в том что класс не хочет работать.
Вот создаю я просто файл vvv.cpp с классом и он не пашет. А ведь должен ведь я просто обьявляю переменные класса. пример файла ![]() ![]() #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #define fntNORMAL 0 #define fntBOLD 1 #define fntSCRIPT 2 class User { public: Picture(); Picture(int,int,int,int); // width, height, #colors, #bits/color component ~Picture(); Picture(char*); void PutPixel(int x,int y,int col) { if(y>=0 && y<(int)leny && x>=0 && x<(int)lenx && col<NumColors) pic[y][x]=col; }; void PrintCharUp(int,int,int,char c); // x,y,color,char void PrintChar(int,int,int,char c); // x,y,color,char void PrintString(int,int,int,char* s); // x,y,color,string void PrintStringUp(int,int,int,char* s); // x,y,color,string void Bar(int,int,int,int,int); // x1,y1,x2,y2,color void Line(int,int,int,int,int); // x1,y1,x2,y2,color void Circle(int,int,int,int); // x1,y1,r,color void FilledCircle(int,int,int,int); // x1,y1,r,color int GetPixel(int x,int y) { if(y>=0 && y<(int)leny && x>=0 && x<(int)lenx) return pic[y][x]; else return 0; } void SetColor(int colornum, int red, int green, int blue); void SetTransparent(int colornum) { TransparentColor=colornum; }; void SetFont(int); // fnt????? SaveAsGIF(FILE* f); private: unsigned char** pic; Word lenx,leny; int usefont; /* GIF Routines */ int BitsPrPrimColor, /* Bits pr primary color */ NumColors; /* Number of colors in color table */ Byte *ColorTable; int TransparentColor; Word RelPixX, RelPixY; /* Used by InputByte() -function */ FILE* OutFile; Byte Buffer[256]; /* There must be one to much !!! */ int Index, /* Current byte in buffer */ BitsLeft; /* Bits left to fill in current byte. These are right-justified */ Byte *StrChr; Word *StrNxt,*StrHsh,NumStrings; void InitGIF(int,int); int AllocStrtab(void); void FreeStrtab(void); int WriteBits(int bits, int numbits); Word FindCharString(Word index, Byte b); Word AddCharString(Word index, Byte b); void ClearStrtab(int codesize); int ResetOutBitFile(void); int Write(void *buf, unsigned len); int WriteScreenDescriptor(ScreenDescriptor *sd); int WriteControlDescriptor(ControlDescriptor *cd); int WriteImageDescriptor(ImageDescriptor *id); int WriteWord(Word w); int WriteByte(Byte b); int BitsNeeded(Word n); int InputByte(void); int LZWCompress(int codesize); }; Добавлено Попробуй пожалуста, у тебя прокомпилится это файл? |
Сообщ.
#4
,
|
|
|
Цитата Aprior @ class User { public: Picture(); Picture(int,int,int,int); // width, height, #colors, #bits/color component ~Picture(); это что такое собственно? если у тебя класс User, то и конструктор, и деструктор должны называться User, ~User соответственно. |
Сообщ.
#5
,
|
|
|
Извиняюсь там было Picture вместо User. Но дело то не вэтом. Я декларирую функции которые потом опредеяю в picture.h который инклудится из picture.cpp. Тоесть тут(в h) класс Picture.
а в pictue.cpp идут функции класса. Вот пример одной из них например ![]() ![]() void Picture::InitGIF(int numcolors,int colorres) { int q, tabsize; Byte *bp; NumColors = numcolors ? (1 << BitsNeeded(numcolors)) : 0; BitsPrPrimColor = colorres; ColorTable = NULL; if (NumColors) { tabsize = NumColors * 3; if ((ColorTable = (Byte *) malloc(tabsize * sizeof(Byte))) == NULL) return; else { bp = ColorTable; for (q = 0; q < tabsize; q++) *bp++ = 0; } } } Дело получается что только в pictire.h |
Сообщ.
#6
,
|
|
|
Aprior, исправь это:
1) функция SaveAsGIF(FILE* f) должна возвращать значение. Вот и напиши об этом.(либо void) 2) если ты пишешь тело функции внутри класса, то после закрывающей } не надо ставить точку с запятой. Ну и исправляй это. У меня компиляется это(см. аттач) Прикреплённый файл ![]() |