sfuo 111 Practically a Master Poster

In <windows.h> ERROR is defined as 0. So unless you were to undefine ERROR before your enum you would be writing

enum ERR_CODE { SUCCESS, 0 };

because the preprocessor just does a "find-replace" for ERROR and swaps it with 0.

A quick solution would be to just define SUCCESS as 1 so then ERROR is 0 and SUCCESS is 1. This is backwards to how you wanted it but unless you undefine ERROR or come up with a different name you cant do anything else.

sfuo 111 Practically a Master Poster

Yeah if you wanted to have it work for 2D and 3D points then you could either overload the function to do both 2D and 3D "hardcoded" or you can use a loop to sum all the squares then take a single squareroot at the end.

Example

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

double Distance(vector<double> pt1, vector<double> pt2)
{
    if( pt1.size() != pt2.size() )
        return 0;

    double sum = 0;
    for( unsigned int i = 0; i < pt1.size(); i++ )
        sum += (pt2[i]-pt1[i])*(pt2[i]-pt1[i]);

    return sqrt(sum);
}

int main(int argc, char *argv[])
{
    vector<double> pt1, pt2;
    pt1.push_back(150);
    pt1.push_back(50);
    pt2.push_back(15);
    pt2.push_back(20);

    cout << Distance(pt1, pt2) << endl;
}
sfuo 111 Practically a Master Poster

I kind of see what you are trying to do with the nested for() loops but it is wrong.

For distance I would just make a function that takes in the two coordinates, or this 4 element array, and then just plug it into the formula.

Also in C++ you want to use the cmath library for math and not the math.h C version.

#include <iostream>
#include <cmath>

using namespace std;

double Distance(int x1, int y1, int x2, int y2)
{
    return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}

double Distance( int coords[4] )
{
    return sqrt((coords[2]-coords[0])*(coords[2]-coords[0]) + (coords[3]-coords[1])*(coords[3]-coords[1]));
}

int main(int argc, char *argv[]) {

    int coord[2*2] = {150, 50,
                      15, 20};

    cout << Distance(coord[0], coord[1], coord[2], coord[3]) << endl;
    cout << Distance(coord) << endl;
}
phorce commented: Thank you! :)!!! +4
sfuo 111 Practically a Master Poster

I'm pretty sure that in Java, like C++, if you pass an array into a function it automatically passes by reference. This means that you do not have return the array to upadte it in main(), since every change done to the array is done where the array is actually stored in memory.

Long story short, just make two void functions and don't bother returning the arrays.

The reason why you are getting errors is because you are trying to return a single integer when in your function def you are saying it will return a pointer to an integer (unless Java can actually return arrays, in which case that would be an array). When you put prevScore[i] that means index i of the array prevScore, whereas if you put prevScore that would give a pointer to the first index of prevScore.

sfuo 111 Practically a Master Poster

There are a few methods for finding the det of a matrix.

Here is an example for using the minors method.

sfuo 111 Practically a Master Poster

Either way I modified it before posting it here so it doesn't matter.

Also, deceptikon showed that lots of parts of the code could be improved so I have to make many changes to it.

sfuo 111 Practically a Master Poster

On line 16 you need scanf("%d", &a[n-1]);

It was not working because scanf() takes in a pointer to the variable in which you want to write to.

The reason why you need to write to n-1 is because if you have an array that has a length of 5 the indicies that you should be accessing for that range are 0, 1, 2, 3, 4 (note that you do not access 5).

sfuo 111 Practically a Master Poster

If you want to you can create aliens using the new operator and store them directly into the vector instead of creating aliens individually then storing the reference of them into this vector of pointers.

std::vector<Alien*> aliens;

aliens.push_back(new Alien());
aliens.push_back(new Alien(100, 200, 30, 30, 1, 172));

You just have to remember to call delete on each element and set it to 0 if you plan on removing/clearing an element (or you can put your vector of aliens in an object like a map or level that manages this for you).

sfuo 111 Practically a Master Poster

This is a timer class that I wrote a while ago (cleaned up a bit for the snippet) for adding delays in some of the games I have written over the years.

Note: I normally have the class functions in a .cpp file but since it looks like I can only post in one "file" I merged them together in what would be a .h file.

The timer basically counts up in miliseconds and can be paused/resumed while maintaining the amount of miliseconds elapsed while the timer was active.

Here is a basic example of counting from 1 to 10 (FIRE!) with a 1 second delay between each increment.

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

int main()
{
    timer aTimer;
    aTimer.Start();

    for( int i = 1; i < 10; i++ )
    {
        std::cout << i << std::endl;
        while( aTimer.GetTicks() < 1000 );
        aTimer.Reset();
    }
    std::cout << "FIRE!" << std::endl;

    return 0;
}
sfuo 111 Practically a Master Poster

The code that you are using for checking who wins is pretty bulky. If you just treat the hands like 0, 1 and 2 and that higher numbers beat lower numbers with the exception that 0 beats 2 then you can just use the mod operator to wrap around and see who wins.

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
    srand(time(NULL));
    int player, cpu;
    char option;
    int wins = 0, losses = 0, ties = 0;

    char hands[3] = {'r', 'p', 's'};

    while(1)
    {
        cout << "Enter (R)ock, (P)aper, (S)cissors, or (Q)uit:" << endl;
        cin >> option;

        if( tolower(option) == 'r' )
            player = 0;
        else if( tolower(option) == 'p' )
            player = 1;
        else if( tolower(option) == 's' )
            player = 2;
        else if( tolower(option) == 'q' )
            break;
        else
            continue;

        cpu = rand()%3;

        cout << "Player | CPU" << endl;
        cout << hands[player] << "    " << hands[cpu] << endl << endl;


        if( player == cpu )
        {
            cout << "Tie!" << endl;
            ties++;
        }
        else if( player == (cpu+1)%3 )
        {
            cout << "Player wins!" << endl;
            wins++;
        }
        else
        {
            cout << "CPU wins!" << endl;
            losses++;
        }

        cout << "Score:" << endl;
        cout << "w: " << wins << " | l: " << losses << " | t: " << ties << endl << endl;
    }

    return 0;
}

I added in a score keeping feature too.

sfuo 111 Practically a Master Poster

First thing you should do is not create your structure within main(). Then you should look at what data types need to be inside of the structure, you have all but the three boolean variables that were listed above. Also you should choose if you want to use a vector or an array for holding the list of students, not both, I would suggest a vector because the number of students varies and if you were to do it with arrays you would need to allocate memory.

struct classroom
{
    int room_number, number_of_chairs, number_of_students;
    string Lecture_name;
    vector<string> students;
    bool window, projector, available;
};

To populate the array you need to make a for() loop that goes goes from 0 to the number of students.

Here is what you can do for getting the students names.

cout << "Please enter the name of each student: " << endl;
string student_name;

//used to ignore the newline char left by reading in numbers
cin.ignore(numeric_limits<streamsize>::max(), '\n'); //need to include the header <limits>
for( int i = 0; i < my_classroom.number_of_students; i++ )
{
    cout << i+1 << ") ";
    getline(cin, student_name);
    my_classroom.students.push_back(student_name);
}

The functions that you need to write later are just going to be taking in two classrooms and then comparing values set in each class.

sfuo 111 Practically a Master Poster

Show us what you have done and we can help you if you state what problems you run into.

We will not just do your homework for you.

sfuo 111 Practically a Master Poster

If a file is up one level from the current directory you can use ".." to access its parent directory.

So you can write #include "../main.h".

sfuo 111 Practically a Master Poster

It sounds like you set up the search directories fine, but doesn't seem like you actually linked the required libraries. Right next to the Search directories tab is the Linker settings tab, click this and then press the add button and add the required libraries to your project (you can just type in the name of the libraries so long as you have set the search directory for the linker right to the root folder of all of the dlib libraries).

sfuo 111 Practically a Master Poster

Yeah sorry my wording may have been a bit misleading. The variable i does have a value of 4; however, acc[i] contains a junk value. So what I guess I should have said is that your array "acc" has a junk value at index i and anything past that (since it is not being set anywhere).

Now what I do not know is why it is crashing for trying to access the index of the array with that junk value. I tried accessing the array at a large index and it just spat out a junk number but when I typed in a value of ~100000 or so it crashed like before. I'm not sure if there is a "magic" number around there but I'm sure there is a hard limit or just undefined behaviour going on. Either way you don't every play out of bounds like that anyways because you could be overwriting other allocated blocks of memory or could just simply crash like this.

sfuo 111 Practically a Master Poster

Show us what you have written so far and we can help you through it if you have any actual questions.

Do not just post up a homework assignment and expect someone to do it for you.

sfuo 111 Practically a Master Poster

Your second for() loop is causing the crash because the first for() loop leaves i at a an index with a junk value since it increments then checks to see if ip_num is 0.

There are two quick ways to fix this:

1) You can assume that ip_num is never zero when entering the loop on the first run and move the break condition to the bottom of the loop.
2) You can start the second for() loop with i = i-1 (or i--).

Either way works and I'm sure there are many other ways to go about solving this problem but I didn't want to modifiy what you had too much.

sfuo 111 Practically a Master Poster

No matter what, collision detection is just going to be a bunch of if() statements. The way that you prevent checking way more objects than you need to is by dividing all your objects into a quadtree or an octree. You then check if your player is within one of the outer nodes and if it is then you work your way in to see what objects you are colliding with.

You should make a program that loops 1000000 times with an if() statement in it and see how many milliseconds it takes. You will be suprised at how little time doing if() checks take.

sfuo 111 Practically a Master Poster

If you use atan2(y,x) it handles divide by zero and what quadrant the angle lies automatically.

sfuo 111 Practically a Master Poster

If you think about it you can divide by just using subtraction and a for() loop. Since you have this function itoa() available I'm assuming you are only using integers, which means you do not have to worry about remainders/decimals.

Not gonna give you any code because you clearly just rewrote the assignment requirements, so give it a shot and if you have any questions post code and outline where you are having issues.

sfuo 111 Practically a Master Poster

You would just need to change a few things.

In this case I would use a vector container for the blocks because it can grow dynamically (arrays can but it is a bit more work). This means you need to include the <vector> header within "lib.h" and since you are not using namespace std globally you need to refer to vector as std::vector (unless you want to just place using namespace std; or using std::vector; in "lib.h").

So instead of having myBlock of type BLOCK in globals you would replace that with vector<BLOCK> blocks; in both globals.h and globals.cpp.

Within the BLOCK class I would just strip it down to

//block.h
class BLOCK
{
    private:
    //The collision box of the square
    SDL_Rect blockBox;

    public:
    //Initializes the variables
    BLOCK(){};
    BLOCK(SDL_Rect pos);

    //Shows the dropped block
    void ShowBlock();
};

//block.cpp
BLOCK::BLOCK(SDL_Rect pos)
{
    //Initialize the offsets
    blockBox.x = pos.x;
    blockBox.y = pos.y;

    //Set the blocks dimentions
    blockBox.w = BLOCK_WIDTH;
    blockBox.h = BLOCK_HEIGHT;
}

void BLOCK::ShowBlock()
{
    ApplySurface( blockBox.x, blockBox.y, blockTexture, screen );
}

Since the block is not going to exist until you "drop" it then you don't really need a boolean variable to keep track of if it has been dropped or not. In this method of managing the blocks you move the block into position by creating it with the constructor, rather than moving it after it has been created.

In order to create the block you should go into the HandleInput() within player.cpp and change the line to …

sfuo 111 Practically a Master Poster

itoa() is in <cstdlib> but is non-standard (meaning it is not implemented by all compilers).

This page shows an example of an alternative method using sprintf().

I'm pretty sure you could also use stringstream.

sfuo 111 Practically a Master Poster

As far as functionality goes it works; however, you shouldn't be using labels/gotos because they are a bad coding habbit and make reading the flow of your code harder. Anywhere you use a goto statement you can replace it with a loop (which is what I did in this case).

Another thing that you should think about is making variable names that actually mean something. When I saw p, f, d, b I had no idea what those were until I looked over the program. So instead of using p as a name for your array of workers you can just call it workers or something descriptive.

You should also know that most programming languages are 0 base indexed so if you want an array that has 10 entries, it starts at 0 and ends at 9.

If you wanted to make this a bit more C++ rather than C you could use strings for the name of the worker and job, also you could use a vector, list or any other STL container that can dynamically resize to however many workers you want to create (or read in from the file if you want to add that feature).

#include <iostream>
#include <fstream>
#include <conio.h>

using namespace std;

struct work
{
    char name[100];
    int id;
    char job[10];
}workers[10];

int main()
{
    int numWorkers = 0;
    int option = 0;
    ofstream file;

    while(1)
    {
        cout << "\nThe db++ Database application\n1-To enter the data\n2-To read the data\n3-To save the data\n";
        cin >> …
piyush3dxyz commented: hey sfuo....i am the beginner in the c++ programming...Its only 2 month of my c++ learning.....but thax for correcting me.... +0
sfuo 111 Practically a Master Poster

Instead of using a switch to manage what key is down just use if statements.

if( event.key.keysym.sym == SDLK_SPACE )
{
    //drop box
}
if( event.key.keysym.sym == SDLK_UP )
{
    //move up
}
if( event.key.keysym.sym == SDLK_DOWN )
{
    //move down
}
if( event.key.keysym.sym == SDLK_RIGHT )
{
    //move right
}
if( event.key.keysym.sym == SDLK_LEFT )
{
    //move left
}
sfuo 111 Practically a Master Poster

I have attached a rewrite of your program because if you ever want future help your code has to be structured.

I would recommend having main.cpp with pretty much just main() in it so you can read the flow of the program and if you want to know what happens in a function then you go open up that header/source file.

Obviously this is just the way I like to structure small games like this and others would disagree/change aspects of it; however, I would hope everyone would agree that having 99% of your code in main.cpp just makes finding errors extremely difficult.

There were many areas where you used the comparison operator (==) rather than the assignment operator (=) which doesn't do what you want and if you have warnings turned off it doesn't tell you that it does nothing.

As far as fixing the problem with the box goes, I changed it so that the dropping of the box is handled by the player class rather than having a seperate handle for the box. The main issue with the box in the first place was that you were making it visible by setting drop to true then right after you released the key you set it to false (which makes the box disappear).

If you have any questions feel free to ask.

ChrisMackle commented: THANK YOU!!!! +0
sfuo 111 Practically a Master Poster

Show us that you have done some work on this by yourself. Post up a program that creates an array, fills it (either hardcoded or by user input) and then your attempt at removing duplicates. After that I will be able to help you out, otherwise you will learn nothing.

sfuo 111 Practically a Master Poster

On line 6 you want to use "rb" not just "r" because just using "r" would read one character at a time. If you have a bunch of integers in your file that are two digits long but are represented as 4 bytes you will be reading only two characters in when you want to be reading in 4.

sfuo 111 Practically a Master Poster

On line 11 your function prototype says that approximateSqrt() takes no parameters so that is where that error is coming from. To fix it change that line to double approximateSqrt(double);

sfuo 111 Practically a Master Poster

Where is your gluPerspective() call? Since I don't see where you are positioning the "camera" or "viewer" you might not have the correct far value.

sfuo 111 Practically a Master Poster

Why don't you show us your code for a linked list and your attempt at getting min, max and counter functions to work.

sfuo 111 Practically a Master Poster

You don't have a display function or an idle function. Not 100% sure if this is the problem since I haven't used glut in a while but from what I remember you need them.

sfuo 111 Practically a Master Poster

Try starting with this

#include <iostream>
using namespace std;

void MyFunction()
{
	//does something
}


int main()
{
	MyFunction();

	return 0;
}
sfuo 111 Practically a Master Poster

The variable ans is initialized but not set.

Right before your for() loop you should write ans = num; otherwise ans will just have a garbage value in it.


EDIT

Or you can change line 7 from cin >> num; to cin >> ans; .

sfuo 111 Practically a Master Poster

Like VernonDozier said, you are declaring 'char c' out of scope but there are also a few other errors within your program.

You are calling the function srand() at the start of the for() loop on each iteration which results in all the characters being the same. The solution to this is to call srand() once either at the start of this function or at the beginning of main() (I would suggest placing it at the start of main()).

The second problem is the range for your rand() function. You had rand() % 26; which will generate a number from 0 to 25 not 0 to 26. So the solution is to just set your maximum to the maximum value in your range + 1.


I did a bit of tweaking and shortened your append section but for the most part it is the same.

Also notice that srand() is not being called here because it should be at the start of main().

string genstring()
{
	string generated_string;
	string stringsize = inputsentance();

	for( unsigned int k = 0; k < stringsize.size(); k++ )
	{
		char c = rand() % 27 + 'A'; //random from "A-["

		if( c == '[' )
			c = ' ';

		generated_string.append(1, c);
	}
	return generated_string;
}
sfuo 111 Practically a Master Poster

The function is not bugged you just didn't read the documentation on this function.

The way you have it set up you have two major problems.

#1 left and right values cannot be equal
#2 near and far must be both positive

If you were to write out the resulting projection matrix using the numbers you passed into the function, then you would get a divide by zero which will cause an error in the function and result in the default values to be used.

Example glFrustum(-ar, ar, -1.0, 1.0, 0.1, 10.0); To see general documentation and how the projection matrix is constructed using the input values you can look here.

sfuo 111 Practically a Master Poster

Best way to figure these types of problems out is by using some paper.

Draw each case you want on paper (in this situation you want to see four ways another box can hit the "hittee") then write out the conditions that have to be met.

Also what happens if you move diagonally into the box?

sfuo 111 Practically a Master Poster

If you do not want the background to move then you will have to draw it first then translate the rest of your scene based on the position of your camera or whatever is moving right now. If you want the background to go forever and move it then you will have to tile* the background image on a huge surface (I wouldn't recommend that).

*Not 100% sure if SDL allows you to tile images but I know in OpenGL you can.

sfuo 111 Practically a Master Poster

I haven't really touched C# before but I'm pretty sure (since in C++ you have to) you need to have BaseClass as an abstract class and then declare someMethod() as abstract within it. This is because you are trying to call a function in SubClass when BaseClass has no idea what functions you have added to SubClass (it only knows the functions/variables that it gives to SubClass).

using System;
using System.Collections.Generic;
using System.Text;

abstract class BaseClass
{
	public virtual void method()
	{ Console.WriteLine("BaseClass method"); }
	public abstract void someMethod();
}

class SubClass : BaseClass
{
	public override void method()
	{ Console.WriteLine("SubClass method"); }

	public override void someMethod()
	{ Console.WriteLine("abstract method"); }

	static void Main(string[] args)
	{
		BaseClass var = new SubClass();

		var.method();
		var.someMethod();
	}
}
sfuo 111 Practically a Master Poster

I take it you want to make a multi-dimensional array so you can store all the words into one array and then use a for() loop to populate/sum the values.

You can merge the two for() loops into one but if you were to join them then why take the values in as a char array and not as an integer rather than converting.

//inputs five strings representing integers, converts the strings to
//integers, sums the values and prints out the total

#include<stdio.h>
#include<stdlib.h>

int main ()
{
	int i, sum = 0;
	int numWords = 5, sizeofWord = 256;

	char words[numWords][sizeofWord];

	for( i = 0; i < numWords; i++ )
	{
		printf("\nEnter something\n");
		fgets(words[i], sizeofWord, stdin);
	}

	for( i = 0; i < numWords; i++ )
		sum += atoi(words[i]);

	printf("\nTotal value entered is %d\n\n", sum);
	return 0;
}
sfuo 111 Practically a Master Poster

If you wanna do a quick n dirty transpose on output just switch your i and j values when printing out. From out[i][j] to out[j][i] will output the transposed matrix assuming that it is a square (#rows = #cols).

If you don't know if #rows = #cols then you do what you are doing now but you must allocate memory for your vector before trying to access it. You can set the size of outtrans by writing

vector< vector<double> > outtrans(out[0].size(), vector<double>(out.size()));

This creates a new 2D vector with the reversed dimensions of "out".

sfuo 111 Practically a Master Poster

For the most part the code is pretty good. You made a few minor errors that would be expected since you are still starting out but you should really work on consistency in indentation since it is harder to read and edit (you will really notice this later on) so you should get into the habit of trying to make your code look nice early on.


I commented in a few places where I made changes.

#include <iostream>
#include <cstdlib> //needed for system() because not all compilers include this header by default

using namespace std;

//the way you are using your functions you can/should have them all return void
void getlist(int[], int&);
void putlist (const int[], int);
void mean_average (const int[], int);
void MinIndex (const int[], int);
void left_rotate (int[], int);

const int MAXSIZE = 50;

int main()
{
	int mylist[MAXSIZE];
	int num_items;

	getlist(mylist, num_items);
	putlist(mylist, num_items);
	MinIndex(mylist, num_items);
	mean_average(mylist, num_items);
	left_rotate(mylist, num_items);

	system ("PAUSE");
	return 0;
}

void getlist(int mylist[], int &num_items)
{
	cout << "Enter the number of Array Elements, Maximum " << MAXSIZE << endl;
	cin >> num_items;

	for( int i = 0; i < num_items; i++ )
	{
		cout << "Enter the next array element: ";
		cin >> mylist[i];
	}
	cout << endl;
}

void putlist(const int mylist[], int num_items)
{
	cout << endl << "Array elements\n";
	for( int i = 0; i < num_items; i++ )
	{
		cout << i << " " << mylist [i] << endl;
	}
}

void …
sfuo 111 Practically a Master Poster

Start with "Hello World!" then add to it.

Then come back and as for help when you have something to show.

sfuo 111 Practically a Master Poster

A quick solution to what you want is to just move your topping selector to the Pizza class since you pretty much have a circular reference with your derived class sitting inside of your base class.

I threw together a simplified version of what I think you are trying to accomplish.

#include <iostream>
#include <list>
#include <string>
using namespace std;

class Topping
{
	public:
	Topping(){};

	virtual void print() = 0;
};

class Cheese: public Topping
{
	public:
	Cheese(){};

	void print()
	{
		cout << "Cheese!" << endl;
	}
};

class Pepperoni: public Topping
{
	public:
	Pepperoni(){};

	void print()
	{
		cout << "Pepperoni!" << endl;
	}
};

class Pizza
{
	list<Topping*> toppings;
	public:
	Pizza(){};

	void AddToppings(string ts)
	{
		for( string::iterator t = ts.begin(); t != ts.end(); t++ )
			switch(*t)
			{
				case 'c':
					toppings.push_back(new Cheese);
					break;

				case 'p':
					toppings.push_back(new Pepperoni);
					break;

				default:
					break;
			}
	}

	void PrintToppings()
	{
		for( list<Topping*>::iterator t = toppings.begin(); t != toppings.end(); t++ )
			(*t)->print();
	}
};

int main()
{
	Pizza *p = new Pizza();
	p->AddToppings("cp");
	p->PrintToppings();
	return 0;
}

I haven't played around with special class patterns but I'm pretty sure that "Pizza" is not a singleton class. In fact what you have is the same as wrapping a few functions and variables in a namespace (since you are not making use of private/protected from the class).

sfuo 111 Practically a Master Poster

Did you figure the problem out? I see it is marked as solved but you didn't edit your post or post your solution.

The problem I see is that you are missing an if() to go with your bottom else statement.

sfuo 111 Practically a Master Poster

Can you post your code then? Because I don't know if you are drawing a background in WM_PAINT: or other problems that might be happening.

sfuo 111 Practically a Master Poster

Yeah if you want it to include 0 and be one less than RAND_MAX for your range.

sfuo 111 Practically a Master Poster

rand()%RAND_MAX should generate [0,32767) meaning the number will never be 32767.

If you want it to include 32767 then just use rand()%(RAND_MAX+1).

sfuo 111 Practically a Master Poster

A normal is a vector and the dot product returns a scalar.

To calculate the normal of a plane when you know two vectors along that plane then you use the cross product (because it gives a vector perpendicular to the plane aka the normal).

The equation of a plane (in Cartesian coordinates) is Ax + By + Cz = D, since the x-axis vector is (1,0,0) and the y-axis vector is (0,1,0) when 'crossed' these vectors that represent the x-y plane make a vector normal to the plane that is (0,0,1) which is the z-axis. The A, B and C coefficients of a plane are the x, y, z values of the vector normal to it (meaning A = 0, B = 0, C = 1 for the x-y plane). And since the origin (0,0,0) is on the x-y plane you can substitute those x, y, z values into the x-y plane equation and you get z = 0 for the equation of the x-y plane (meaning any point with a z value of 0 will be on the x-y plane).

I am not sure what you mean by only including dots that have normals with angles of 80 to 100 degrees because the definition of a vector normal to a plane is one that is perpendicular (90 degrees) to it.

Can you post some code or a screenshot to see what is going on because I am having a hard time understanding what you …

sfuo 111 Practically a Master Poster

Without actually knowing how it is implemented and by only playing around with these two classes it seems when there is a name conflict (in this case x) the default scope to be used is that of the class that is calling it. When inheriting another class the class that is being inherited is added to the scope of the "inheriter" if there is no conflict.

For example

class B
{
	public:
	int x;
};

class D: public B
{
	public:
	int x;
};

would result in 'D' looking like

class D: public B
{
	public:
	int D::x; //in the default scope so 'D d.x' would look at this
	int B::x; //name conflict so would need to use 'D d.B::x' to access 
};

As for implementing a structure like this in C I would say it is impossible to put two variables with the same name into the same structure since there are no namespaces or 'built-in' inheritance in C. I came across this page and it goes over how to make classes with functions and inheritance in C (I didn't read it that much just scrolled through it).

sfuo 111 Practically a Master Poster

If this is all the code you have for your DC and drawing then the problem is that you aren't drawing to the correct DC that you might think you are.

In WM_CREATE: you are creating an HDC object and then setting it to the current DC. After this case is finished none of that information is kept. The way I think you have it, but I cannot tell because I do not see all your code, is that you have hDC declared globally but not initialized to anything so the line that says HDC screen DC; and replace screenDC with hDC in WM_CREATE: