|
Sadaf Rehman Najmi wrote: because when we working with header files thn we should memorize name of all header files and function related to these files You trade such a little effort for a whole bunch of state-of-art functionality.
Veni, vidi, vici.
|
|
|
|
|
Don't you think that if it would be easier without header files, that millions of coders before you hadn't found out about that a long time ago?
The memorization isn't an issue: In C++ the usual way of organizing your code is that you use one header file for the declaration of each class, and one corresponding source file for the implementation of each class. You use the same base name for the header file and the source file, only the suffix is different!
Moreover, you normally use an integrated development environment (IDE), which helps you organize your program, much like a file explorer. It will help you jump from a given variable or type or class in your code directly to the location in your code where it's defined. You really don't need to memorize anything!
The application I work on has more than 3 million lines of code and consists of several thousand files - I don't even try to memorize where everything is! That is what the IDE does for me. And it works: If someone reports a bug I can usually locate the rough area of code where something goes awry within 10-20 minutes - even if I've never seen that code before!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
As suggested above, yes you can.
However, it's entirely pointless to do so! Include files help you organize your program in managable chunks, and let you use preexisting libraries, including all system functions. Likewise, if your program itself provides useful functions, you can put your function declarations into a header file so others can use it too.
Which begs the question: why are you even asking?
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Stefan_Lang wrote: why are you even asking? Probably an interview question.
Veni, vidi, abiit domum
|
|
|
|
|
Yes you do this in C++ but its not a good approach we should always include header files in our programs. Its a good practice.
|
|
|
|
|
Hi,
Kindly let me know, How do I change the torus color into Red instead Grey color and what command lines are required to do the same.
Thank you
Here are codes:
#include <gl/glut.h>
#include <stdlib.h>
static int spin=0;
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
GLfloat position[] = {0.0, 0.0, 1.5, 1.0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glPushMatrix();
glRotated((GLdouble) spin, 1.0, 0.0, 0.0);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glTranslated(0.0, 0.0, 1.5);
glDisable(GL_LIGHTING);
glutWireCube(0.0);
glEnable(GL_LIGHTING);
glPopMatrix();
glutSolidTorus(0.275, 0.85, 8, 5);
glPopMatrix();
glFlush();
}
void reshape (int w, int h)
{
glViewport(0,0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat) w / (GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse(int button, int state, int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state == GLUT_DOWN)
{
glEnable(GL_LIGHTING);
spin = (spin + 30) % 360;
glutPostRedisplay();
}
break;
default:
break;
}
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutInitWindowPosition(100,100);
glutCreateWindow("My Torus with Mouse Click");
glutDisplayFunc(display);
init();
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
|
|
|
|
|
M Riaz Bashir wrote: glutSolidTorus(0.275, 0.85, 8, 5);
Wild guess. Three of these four parameters represent RGB colors. For RED, you will have value 255, 0, 0. So try following line, or play with these paramaters using hit n try.
glutSolidTorus(255, 0, 0, 0);
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Hello, I am making a Ball Breaker game and i have got some unusual crsh error in main when i call b.fill_bricks(); and when i press esc button it crashes.if i use it without class,everything works fine but in class it won't.Plz give me a solution.
#include <allegro.h>
BITMAP *buffer;
class Bricks {
public:
int bricks_array[4][5];
void display_Bricks();
int fill_bricks();
};
int Bricks::fill_bricks()
{
for(int i = 0;i<4;i++)//layer
{
for(int j = 0;j<10;j++)//brick_no
{
bricks_array[i][j] = 0;
}
}
return 0;
}
void Bricks::display_Bricks()
{
int x=50,y=25;
for(int i = 0;i<4;i++)//layer
{
for(int j = 0;j<10;j++) //brick_no
{
if(bricks_array[i][j] == 0)
{
rect(buffer,x,y,x+100,y+50,makecol(225,225,225));
}
x += 50;
}
y += 25;
x = 50;
}
}
void init();
void deinit();
int main() {
init();
Bricks b;
b.fill_bricks();
acquire_screen();
b.display_Bricks();
draw_sprite(screen,buffer,0,0);
release_screen();
while(!key[KEY_ESC]){}
//deinit();
return 0;
}
END_OF_MAIN()
void init() {
int depth, res;
allegro_init();
buffer = create_bitmap(640,480);
clear(buffer);
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
}
void deinit() {
clear(buffer);
clear_keybuf();
/* add other deinitializations here */
}
|
|
|
|
|
You have defined bricks_array[4][5] , but then you try and fill 4 rows each of 10 columns, so you are corrupting some memory.
for(int i = 0;i<4;i++){
for(int j = 0;j<10;j++) {
bricks_array[i][j] = 0;
}
}
Veni, vidi, abiit domum
|
|
|
|
|
thanks..i never got attention at that point..such a silly mistake. But thanks. Its working fine now.
|
|
|
|
|
An easy mistake, but most programmers I know have made it a few times in their lives. Using constants to set the values helps to avoid issues such as this, for example:
static const int ROWS = 4;
static const int COLUMNS = 5;
BITMAP *buffer;
class Bricks {
public:
int bricks_array[ROWS][COLUMNS];
void display_Bricks();
int fill_bricks();
};
int Bricks::fill_bricks()
{
for(int i = 0; i < ROWS; i++) {
for(int j = 0; j < COLUMNS; j++)
Veni, vidi, abiit domum
|
|
|
|
|
I have a window created with CreateWindowEx, with a caption. When I load the text using EM_STREAMIN the opening line of the text goes into the caption, replacing the intended title. How do I prevent this, so as to retain the intended caption ?
|
|
|
|
|
You need to show us the code that causes this to happen.
Veni, vidi, abiit domum
|
|
|
|
|
What exactly do you mean by "with a caption". RichEdits are the same as a 'standard' edit, in that they don't have a caption. They simply contain text that may be edited by the user. In the case o a RichEdit, formatting and OLE objects are supported too. But captions? Nah, not according to any of the dozens of documents I've ever read on the matter. I've added captions to them, but that's through additional code - not through any inherent functionality of their own.
Any caption that you have is a result of code that you have that we can't see. If you'd like a solution to your problem, you'll have to show us how you got into the predicament in the first place. Or as Richard said, you'll need to show code to get an answer.
|
|
|
|
|
how to Generate list of processes which are accessing file /FOLDER/ Directory ??
.
as exactly "UNLOCKER" works!!
is there any function available in WINAPI for this?
|
|
|
|
|
Hello. How do I extract RGB colors from a byte ? Thanks
|
|
|
|
|
|
If you have 1 byte representing a color then it is probably just the index of the full RGB color inside the corresponding palette.
Veni, vidi, vici.
|
|
|
|
|
Just mask the bits[^] out
(do you still need some help ?)
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
|
|
|
|
|
I want to use a pointer to get an array elements value.
char s1 = {1,2,3,4,5,6,7};
int t1 = *(int*)(&s1[2]);
I think t1 value is 3456,but in fact, it returns a strange value looks like an address value.
But I make a struct type like:
struct TestStruct {
char c1;
char c2;
char c3;
char c4;
}ts1;
ts1 = *(TestSTruct*)(&s1[2]);
then I can get ts1.c1 = 3, ts1.c2 = 4, ts1.c3 = 5,..
Can anybody give me some hint?
modified 13-Dec-13 2:19am.
|
|
|
|
|
|
In both cases your syntax seems to be somewhat confused. For case 1 why not just:
char s1[] = {1,2,3,4,5,6,7};
int t1 = s1[2];
In case 2, you are casting an array to a structure which will in many cases break your code. Structures will often have their elements aligned on word boundaries so what you think is elemnt n of the array is actually something completely different. If you want to use a structure then fill it with your data in the first place. Don't use casts unless you know that the data will be in the locations you think it will.
[edit]
Added [] after s1 , as Stefan pointed out.
[/edit]
Veni, vidi, abiit domum
modified 13-Dec-13 5:00am.
|
|
|
|
|
shouldn't this be
char* s1 = {...};
rather than
char s1 = {...};
?
The latter is just a single char, and using s1 as an array will lead to invalid memory references; most likely such attempts will access arbitrary adresses on the stack (i. e. other stack variables or parts of them).
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Forgot to indicate, s1 is a global array.
In fact, I tested, the method works, the weird value is because I use %d to print, when i change %d to %x, it prints correct result
|
|
|
|
|
My point was that the code you posted produces a compiler error in line 1. I suggested you should correct it in your posting so we can see what you your code really looks like, rather than guessing what it might be.
The difference between %d and %x is that the former expects a signed integer variable and prints it as such, whereas the latter will completely ignore the type of the variable and print whatever it finds in unsigned hexadecimal. In general, I doubt that is what you wanted, although for values lower than 10 it may look like it. If %d produces a different output than %x for a variable of type char , then the only relevant difference is signed/unsigned, so %ud shoud print the same as %x .
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|