What do you think the code is doing? Add some comments.

lancevo3 commented: Very helpful in attempting to solve my issues. +1

Errr, ignore that last part. Sometimes I'm unclear.

[code=cpp]Student student;
for(int subject = 0; subject < 4; subject++){
string code;
int cu;
char pass_or_fail;
inFile >> code;
inFile >> cu;
inFile >> pass_or_fail;

//subject == loop variable
subjects[subject].setCode(code);
subjects[subject].setCU(cu);
subjects[subject].setPF(pass_or_fail);

}[/code]

I meant something like that. That's the "input" loop. Now, as you can see, this one is for subjects, but you should also create one for students for their variables. Same goes for output. If you don't know how, first write the code for reading in 1 student, then simply loop that. ;)

Hey guys,

I was wondering, with this code:

main.cpp
[code=cpp]

include <iostream>

using namespace std;

class car {
public:
car (float speed) :
speed(speed) {}

car () :
        speed(0) {}

void cruise(float speed) {
    this->speed = speed;
    cout << "New speed: " << getSpeed() << endl;
}

void brake(float power) {
    this->speed -= power*power/4;
}

float getSpeed() {
    return speed;
}

private:
float speed;
};

class racer : public car {
public:
void boost(float power) {
cout << "BOOST! ";
cruise(getSpeed() + power*power/3);
}
};

class tank : public car {
public:
bool shoot(float aimTime) {
cout << "Shot ";
if (aimTime > 5.0) {
cout << "hits!" << endl;
return true; //hit!
} else {
cout << "misses!" << endl;
return false; //miss!
}
}

};

class racetank : public racer, public tank {
public:
bool boostShoot(float power, float aimTime) {
boost(power2);
return shoot(aimTime
2);
}
};

int main() {
racetank mycar;
mycar.car::cruise(50);
mycar.boost(20);
mycar.car::brake(5);
mycar.boostShoot(35, 1.4);

return 0;

}
[/code]

MinGW's GCC gives me these errors:
[code]D:\MyDocs\Code\InheritThis\main.cpp||In function int main()':| D:\MyDocs\Code\InheritThis\main.cpp|62|error:car' is an ambiguous base of racetank'| D:\MyDocs\Code\InheritThis\main.cpp|64|error:car' is an ambiguous base of `racetank'|
[/code]

How come the compiler still complains about ambiguity?

It knows the function is not overloaded (?)
It knows the function is not virtual.

Can't the compiler be sure that when I call the function like that, it's the same function?

Thanks in advance,

PS:
I know the solution to this is to use virtual inheritance, but I was wondering why C++ works ...

NicAx64 commented: hmm nice and smart bug , I think I find something new +1

Here are two examples I created and use as a reference, maybe they are of help:

[code=c]
/*
* Playing around with WinSockets
/

include <stdio.h>

include <winsock.h>

int main (int argc, char **argv){
WORD wsaVersion;
wsaVersion = MAKEWORD(2,2);
WSADATA wsaData;
SOCKET sock1;
int wsaerr;

wsaerr = WSAStartup(wsaVersion, &wsaData);
if (wsaerr != 0){
printf("\nWinsock not found");
return -1;
}
printf("Winsock found");

sock1 = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock1 == INVALID_SOCKET){
printf("Initializing socket failed: %ld\n", WSAGetLastError());
WSACleanup();
return -1;
}
printf("\nSocket() works");

WSACleanup();
return 0;
}
[/code]

[code=c]#include <stdio.h>

include <winsock2.h>

int main(int argc, char **argv){
WORD wsaVersion = MAKEWORD(2,2);
WSADATA wsaData;
int wsaerr;

wsaerr = WSAStartup(wsaVersion, &wsaData);
if (wsaerr){
printf("WSAStartup failed, exiting.");
return -1;
}
SOCKET somesock;
somesock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

if (somesock == INVALID_SOCKET){
printf("Socket() failed, exiting.");
WSACleanup();
return -1;
}

struct sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr("127.0.0.1");
service.sin_port = htons(12344);
if (bind(somesock, (SOCKADDR*)&service, sizeof(service)) == SOCKET_ERROR){
printf("Bind() failed, exiting.");
closesocket(somesock);
WSACleanup();
return -1;
}

closesocket(somesock);
WSACleanup();
return 0;
}[/code]

Here's are tiny server/client applications. I don't guarrantee they work or are the holy grail of winsock programming, but if they still work then they are good references. ;-)

basicServer.c
[code=c]/BasicServer.c/

include <stdio.h>

include <winsock.h>

include <string.h>

define BUFFERSIZE 511

int main(int argc, char **argv){
if (argc < 3){
printf("Usage: %s <message to send to client> <ip to listen to>\n", argv[0]);
return -1;
}
SOCKET sock, accepsock = SOCKET_ERROR;
WSADATA wsaData;
WORD wsaVersion = MAKEWORD(2,2);
int sizeOf, wsaerr;

struct sockaddr_in sockinfo, clientinfo;
sockinfo.sin_family = AF_INET;
sockinfo.sin_addr.s_addr ...

Salem commented: Looks good. +26

It is only a pointer, don't worry. It's a pointer that points to pointers.

The struct declaration indeed only reserves one pointer, not an array or anything.

However, I guess you want to have *students in your struct. An "array" of students, right? That makes a bit more sense than what you have now (which resembles a 2D array of students).

By the way blrjohn, you could also try and fire up a console and execute your program from there. It won't disappear then. I dunno on which OS you are, but guessing it's Windows (80% market share or something eh):

Go to:

Start -> Run

type in "cmd"

Hit enter.

Behold the almighty black screen with often blinking cursor! :D

Typing in "cd" and then a path will let you change your directory. Type in "help" if you're in need of more help. Mastering the console is pretty convenient for developers.

Salem commented: This is how it should be done. +20

That's a C++ program btw, not C.

To make it C:

[code=C]#define _WIN32_WINNT 0x0500

include <windows.h>

include <stdio.h>

include <math.h>

int main()
{
HWND console = GetConsoleWindow();
HDC dc = GetDC(console);
int pixel = 0;
unsigned int loopcounter = 0;
unsigned int loopmax = 126;
COLORREF C1= RGB(255,0,0); //red
double i = 0;

for (loopcounter = 0; loopcounter < loopmax; loopcounter++)
{
    SetPixel(dc,pixel,(int)(100+50*sin(i)),C1);
    pixel++;
    i += 0.05;
}
ReleaseDC(console, dc);
getchar();
return 0;

}
[/code]

And link it with gdi32.

Nick Evan commented: Thanks for the heads up! +6

Not to be an asshole but poster says he wants to capture and store image data from a webcam. That's pretty specific, not?

jephthah commented: haha +2