thelamb 163 Posting Pro in Training

It really makes sense what you're doing wrong... I think you basically wrote the code that sents newNode->x and then copy/pasted it, changing 'x' to 'y'.

Look at the things that you are doing for _both_ x and y, and think about if it makes sense...

Let me state it a little differently:
You do:
-> Ask user for X
-> Create newNode
-> Initialize newNode->x
-> Ask user for Y
-> Create newNode
-> Initialize newNode->y

What if you would do this:
-> Ask user for X
-> Ask user for Y
How would you continue this? Create two newNode's or one?

thelamb 163 Posting Pro in Training

Ok you've missed 2 of my points:
1 - Why is item public? You create a wrapper to perform actions on the item(push, pop etc.) but since item is public, it is also possible for code to directly access it (e.g. me.input.pop()), that defeats the point of having this wrapper class.

2 - I guess you didnt understand what I meant with the comment about push...
You comment that all the STL implementations take an argument to push(), which is absolutely correct. With my comments I did not tell you to remove this argument, I suggested to change it to make the behavior of your push() function more clear to a user.
I suggest you read up on references in C++ and if you don't understand why push should take a 'const string&' rather than a 'string*' come and ask what exactly you don't understand ;)

thelamb 163 Posting Pro in Training

A few things:

Why is 'item' in the test class public?
In your wrapper class you perform some operations twice:

string top(){
    item.top();
    return item.top();
}
// Why not:
string top(){
    return item.top();
}

Also, your push takes a string* as arugment, but it is not clear if 'push' is actually going to change something to the argument.

void push(string *ps){
    // It is possible to change the string here, for example:
    *ps = "Haha I changed your string!";
    item.push(*ps);
}

The user of your class normally has no idea how you implement your push, so a better approach is:

void push( const string& ps ){
        ps = "Haha I changed your string"; // <-- ERROR! ps is a const&
        item.push(ps);
    }

I assume you made it a pointer so that the string is not copied all the time, but if you use a reference(&) there also will be no copy.

thelamb 163 Posting Pro in Training

Why does it obviously not work if you copy just the executable?

You'd mostly only need an installer when releasing a big project... if it's just some executable what would the installer do to make it working on the other's PC?

thelamb 163 Posting Pro in Training

By building the solution, it is already creating the exectutable(check your project settings for 'output directory'.

Since you are building with the Express edition of Visual Studio, the 'C++ redistributables' need to be installed on any computer where u wish to run your executable(mostly it is).

thelamb 163 Posting Pro in Training

As far as I can see, you are never calling calcArea().

thelamb 163 Posting Pro in Training

We don't know how your teacher grades.. and what you have learned so far that you could apply. So saying yes it is correct would be a bold statement.

But this is indeed a data structure that holds the information listed. However you forgot to initialize the 'city' part of the structure. On the other hand if you just need to store the population and saving factor you could remove the string city.

thelamb 163 Posting Pro in Training

Yeah reading up on C++ is probably the best way. And please forget about using system("PAUSE") (there are sticky's on this forum explaining why and how to do it correctly).

thelamb 163 Posting Pro in Training

Well actually, you are writing C code here.. in C++ you don't really use malloc explicitly.

So I suggest you read some basic C++ books (there is a forum-sticky that lists some good ones). To get an idea of how to do things

thelamb 163 Posting Pro in Training

Are you compiling a 'debug' build?
If so, you should get an ASSERT much earlier.

Look at your aggiungi function (btw, why are you mixing english and other-language variable/function names? It can become very confusing).

In this aggiungi function, why are you creating r2 on the heap(e.g. why are you using malloc).
Let's assume you keep the malloc, then at some point you need to free it, the prototype for free is:
free( void* )

But you are handing over a reference to r2 (&r2), that will evaluate to 'struct Record **' instead of 'struct Record *'.

Then in the calcella function, you are doing:

free(r);
        free(&r);

Which can never be right.

After you fix all the free's the program still crashes though.. but that is an excersize for you ;)

thelamb 163 Posting Pro in Training

I think it's best you try and explain what you are trying to accomplish.
At the moment the use of strncpy isn't what it's intended for.

It seems to me you have a pollution_day array that you're trying to fill in the set_pollution function... but it's unclear what you want to fill it with.

In any case, you're kind of writing C code here (which can work of course but using C++ containers like vector may be much easier/more table ).

So if you give us some more details we may be able to help you come up with a better design.

thelamb 163 Posting Pro in Training

Ok, so show us how you're reading the file and how(where) you're resetting the file pointer

thelamb 163 Posting Pro in Training

Define "Doesn't really work" .. what are your results? What do you expect?

thelamb 163 Posting Pro in Training

There definitely is, and it is a big part of the power of C++.
What you're looking for are called "templates", there are a lot of references about it on Google but of course if something is unclear you can always post here and someone will explain ;)

Edit:
You could also improve your design. When you are writing classes in C++ you should always ask yourself "Is there any shared data between these classes" If so, you can consider using a base class and let the Vertex and Edge classes inherit from this.

You could then write your algorithm function to take a "BaseClass*" or "BaseClass&" as argument, and C++ will figure out by itself if you've passed a Vertex or an Edge.

Assume that you have a BaseClass that both Vertex and Edge inherit from in this example:

int myFunction( BaseClass* pBase )
{
   pBase->Element; 
}

int main()
{
   BaseClass* pVertex = new Vertex();
   BaseClass* pEdge   = new Edge();

   myFunction( pVertex );  // accesses pVertex->Element
   myFunction( pEdge );    // accesses pEdge->Element
}
thelamb 163 Posting Pro in Training

I am not sure how to get the input from the commandline from the user.

Do you want the user to type something in the console? In that case you get 'get' this input with "cin", it works simmilarly to cout.

If you want a user to start your application with some arguments( "MyApplication.exe Some Input Here" ) you need to modify your main function a little:

int main( int argc, char** argv )
{
    for( int i = 0; i < argc; ++i )
        cout << "Argument "<<i<<": "<<argv[i]<<"\n";

}

The arguments will be stored in argv, and the number of arguments that are stored is set in argc (not that argv[0] will be your Executable name, so MyApplication.exe)

thelamb 163 Posting Pro in Training

Very well done, it's looking good :D.

The 'win checks' is a tricky one... I'm sure there is some standard way to do this but I've never had to do something simmilar. Maybe think of the problem differently:

Instead of checking the entire field every time, you could move the check to the function where you draw a new object, you know in which position the new object is drawn and the type of the object. So here you can check if the same object is anywhere near the new position, if it is check if there is a 3rd one in the correct position next to that.
The code might end up more unsexy but that's about the only thing I can come up with after my first coffee.

Atleast it will save you from calling all 3 win check functions, which shouldn't be necessary as crosses can only win when it's crosses turn, and you only have to check for a draw when all tiles are full.

thelamb 163 Posting Pro in Training

Are you calling your destructor function explicitly? If so.. you probably shouldn't ;)

thelamb 163 Posting Pro in Training

Yes, I find the use of C functions like sprintf dirty in C++ code. I guess I should've mentioned that this is somewhat a personal preference and not a strict rule though ;).

So I guess now the OP has all the information to chose between tedious(yes, it is a better description) or (in my eyes) cleaner solution ^^.

thelamb 163 Posting Pro in Training

stringstreams are a much cleaner solution than dirty C sprintf functions and should definitely be preferred when writing C++ code

thelamb 163 Posting Pro in Training

There is a lot of information available on the internet that explain virtual functions and all the others things you mention much better than I would be able to explain in a post here.

But what I said before is still true to start with.. ask yourself the questions I mentioned, especially about which classes have information in common.

If you think that some of the classes have something in common, you can put this information in a 'base class' and let all the other classes that need this information inherit from the base class.

Take for example a car and a bus. They both have wheels, the both have an engine etc.
So you could create a base class 'vehicle' that contains information about wheels and engines and let the car and bus classes inherit from vehicle:

class vehicle
{
   int m_NumBerOfWheels;
   int m_HorsePower;
};

class car : public vehicle
{
   car() { // we can use m_HorsePower etc. here }
};

I ommitted the constructor/destructor and public/private modifiers but u get the idea...
Now every vehicle needs a way to start, but let's assume that a car and a bus start in a different way, this is where you could use virtual functions:

class vehicle
{
   virtual bool start()  // Default start() function
   {
       cout << "vehicle starting\n";
   }
   virtual bool stop() = 0; // PURE virtual function, means every class that inherits from vehicle MUST implement it
};

class car …
thelamb 163 Posting Pro in Training
#include<iostream.h>
void hi(void)
void name(void)
int main()
{

First of all, you should include <iostream>, not <iostream.h>
Secondly, you should tell us in what line the error is.. or at least copy/paste the exact error.
But I tried to compile your code and the error is in the 3 lines that I pasted above: Now if you look at just those lines, what do you think is missing?

thelamb 163 Posting Pro in Training

No one is going to design this for you since you don't show us that you have made any effort at all to think about the problem (other than how to write your question and copy/paste the problem description).

You know that you want to use OOP concepts to write this game... so start thinking: What kind of objects do you have in this game? Do any of the object have anything in common? Which objects interact with eachother? By asking yourself those kind of questions you can decide about a design.

So start thinking and ask _specific_ questions here if there is something that you do not understand, or you would like to discuss a design approach that you made.

thelamb 163 Posting Pro in Training

You're confusing compilers and IDE's. Microsoft Visual Studio is an IDE, the code is compiled with the Microsoft C++ compiler.

A lot of people have different opinions about IDE's, you're just going to have to try one for yourself and see if you like it, I don't think there is any perfect IDE but Visual Studio definitely is not a bad option. Personally I use Code::Blocks with the Microsoft C++ compiler (I also develop on Linux and Code::Blocks is cross-platform, so I like the fact that I can use the same IDE on Windows and Linux with all the same settings).

There is a free version of Visual Studio (Express edition) however if you use this, you need to install the Microsoft Redistributable package if you want your code to run on someone elses machine (ususally this is already installed but not always). This is not a problem with the paid versions of Visual Studio.

So if you want to develop games for just Windows I would say download the Visual Studio express edition and have a go at it.. if you really like it you can consider buying one of the full packages.

thelamb 163 Posting Pro in Training

First of all, you should use code tags, no one is going to read through your code like this.

Secondly, if you've written this code then the errors should make perfect sense. Did you even check the lines where the errors occur? If so, you need to be more precise with your variable names. For example you are mixing JulianDate and theJulianDate.

thelamb 163 Posting Pro in Training

Good, then that makes it time to move away from the dirty C-arrays and use proper C++ classes. Show us how far you get ;)

thelamb 163 Posting Pro in Training

Well done, I'm impressed that you straight got the use of % to do your 'creating the tiles loop' ;).

In C++ it is rarely necessary to work with arrays directly, it is very error-prone and mostly even confusing. So unless you're doing some low-level stuff where it is necessary(either because you don't have a choice or because the code is performance-critical) stick to C++ containers like vector etc.

It will make your code much more maintainable, as you don't have to make any assumption about the size of tInfo (vector takes care of allocating extra memory internally).

I do have one question about your last code snippet though:
Looking at just the 14 lines that you pasted, what can be a simple improvement to your code that both benefits speed and 'lines-of-code'?

thelamb 163 Posting Pro in Training

Your do..while statemen is wrong (so you are getting the error at line 15 I guess, not at 9 where you are also using cin). This indicates that cin itself isn't the problem, but something closely before the line where the error is.

A do/while is written like:

do
{
   doSomething();
} while( condition );  //<-- don't forget the ; here
thelamb 163 Posting Pro in Training

His approach isn't C-Style as the int i, ii; is not at the start of a scope block.
He does re-use the 'i' in two for loops, which is asking for confusion.

Anyway Ral78 what they are trying to point out is that it is good practice to make a variable's scope as short as possible (do you know what a 'scope' is?). So it is better to write code like:

for( int i = 0; i < n; ++i )
{
   // we can use i here
}
// here we can _not_ use i anymore

for( int i = 0; i < n; ++i )
{
  // Here we can use the new i again
}
// Nope, can't use i anymore
thelamb 163 Posting Pro in Training

Good job, you got my point.

But there are ways to improve your code. Firstly: you are basically writing C code, don't you want to use C++ constructs?

Secondly, 'hard-coding' the 1 though 9 values for HMENU should ring some alarm bells. What if you want to have more than 9 windows later? You'll need to modify the tInfo struct, and find the for( int i = 0 i < 9 .. ) loop again to change the 9. That works fine for this example, but my guess is that you don't want to stop coding after this and move on to bigger projects ;).

Can you make it dynamically fill the tInfo structure? And if you have nothing against C++ constructs, maybe use some kind of container to simplify the code?

Edit:
Also, the 'creating the tiles' portion can be improved. Think about doing it in some kind of loop, there are only a few parameters that are changing and they change in a fairly constant way, this will also make it much easier to update the tInfo structure, rather than writing the update code 9 times.

thelamb 163 Posting Pro in Training

First of all: Do you understand why there is only one beep and after that never again?

Secondly, let's think about your problem. You have an X number of objects(windows) and you want them to perform an action only once. So for each of these objects you can store a 'state' whether they have already performed the action or not.

Knowing this, what parameter/variable is unique for every object? This is a parameter that you can associate with the state variable.

In the end it comes down to storing the unique_object_identifier + state and searching for the unique_object_identifier in the TitleProc, to get the state and based on the state perform the action or not.

vadalaz commented: Thanks! +0
thelamb 163 Posting Pro in Training

A much better (C++) solution would be to move away from C-Style arrays and use a container class like 'vector'.

This will also allow you to use std algorithms like std::sort to sort the vector

thelamb 163 Posting Pro in Training

webhost.com won't allow you to connect to the MYSQL database remotely.

Try to ping the domain:
C:\Users\thelamb>ping mysql9.000webhost.com
Pinging mysql9.000webhost.com [10.0.0.23] with 32 bytes of data:

10.0.0.23 is the local ip on 000webhost.com where they run the mysql server.

Kesarion commented: thanks +1
thelamb 163 Posting Pro in Training

I don't really understand what your plan is... but if I am correct this should be equivalent and clean:

class PersonClass
{
  public:
  std::string Name;
  virtual void GoToWork(){}; // Or GoToJob, whatever suits you
};

class LawyerClass : public PersonClass
{
  public:
  void GoToWork(){ cout << "Going to Court"; }
};

class DoctorClass : public PersonClass
{
  public:
  void GoToWork(){ cout << "Going to surgery"; }
};

int main()
{
     PersonClass* person = new LawyerClass;
     person->GoToWork();  // prints: Going to Court
}

As long as you reference person through a pointer or a reference it will 'know' that person is a Lawyer.

Besides that you now have a much cleaner interface (same function no matter what type the object is) you also got rid of your dynamic_cast. dynamic_casts really should be used with care, if you think you need it.. think twice: you probably don't.
There are uses of course but mostly there are better alternatives.

thelamb 163 Posting Pro in Training

Your result is compiler (option) specific.
You're probably compiling with "Optimize for speed (O2)", if you remove this option you will probably not see EQUAL being printed (at least not with my compiler).
So try to compile with different options, and print the addresses of a and b ;).

In any case, it really makes sense that you are comparing pointers, after all.. a and b _are_ pointers, and you are comparing them... there is no reason for the compiler to care about what a and b point to in the comparison.

thelamb 163 Posting Pro in Training

And let's explain why:

On line 44, you call searchArray with items and itemA.
items and itemA both have different types, but your searchArray expects them to be the same type (both of type 'T'). If you apply firstPerson's fix, 'answer' and 'index' can be of different, or the same type.

thelamb 163 Posting Pro in Training

First of all, use CODE TAGS when you are pasting code!

Secondly, you are never calling your function.

Finally, look at the loop that you have in your function.
You start b at 0, and you want the loop to run only if b is greater than 1 and less than 32. How is b going to get creater than 1 if u start at 0?

thelamb 163 Posting Pro in Training
void main()

Are you sure this is correct? If so.. why?

your enemy variable is a local, automatic variable. This means it will be destructed when it goes out of scope(do you know what a scope is?).

If you wish to delete the variable at some 'random' point in your code you need to ensure that it goes out of scope at this point OR you need to dynamically allocate the object.

Example:

int myFunction()
{  // start of myFunction scope
    int myInt;
    int* myDynamicInt = new int( 5 );
    while( true )
    { // start of while scope
         int mySecondInt;
    } // end of while scope (mySecondInt is destroyed here).

    delete myDynamicInt; // destroy myDynamicInt
}  // end of myFunction scope (myInt is destroyed here)

If you would have forgotten the 'delete myDynamicInt' in my example, it would cause a memory leak (myDynamicInt would never be cleaned up).

I hope that clears things up a little.

thelamb 163 Posting Pro in Training

@Chris :

That's not really a C++ problem, a programmer should not use a reference to change a variable in a function, if the variable is to be changed he should use a pointer.
A reference can be used to 'speed up' functions that take large data structures as arguments, but in this case it should be a const reference to indicate that the passed variable is not going to be changed.

Stroustrup mentions this specifically in his "The C++ Programming Language" book.

thelamb 163 Posting Pro in Training

You should learn the basics of C/C++ before you attempt to make a game cheat/hack.
This is simply copy/pasting code and then copy/pasting the error here.

Btw, if you read the errors it tells you exactly what to do.

thelamb 163 Posting Pro in Training

Yes that is absolutely correct. As I said, if you call a function through a reference or a pointer you will call the function on the derived class.
If you cast the pointer to a BaseClass, you lose any relation with any derived classes(this is called slicing). Basically "A temp" has no idea that it was cast from a derived class, while "A* temp" will have that 'knowledge'.

What I still don't understand is why this doesn't solve your problem:

void B::func4() { A::func1(); }
thelamb 163 Posting Pro in Training

This is the correct (and beautiful) behavior. When you access a member function through a reference or a pointer of a base class, the derived class's function will be called.
This allows you for instance to store a container of BaseClass* and store many different DerivedClass objects, without having to keep some kind of type-specifier in the base class.

I've never had to call a base virtual function explicitly and I don't really understand why you have a function in B specifically to call another function in A.
According to: http://www.java2s.com/Tutorial/Cpp/0180__Class/Callbasevirtualfunctionexplicitly.htm

This should work(I did not try to compile it):

b.A::func1( ); // Calls the base version
thelamb 163 Posting Pro in Training

You declare fgetline as a member function of the UTAevent class.
Except, when you define it you do not tell the compiler that the definition is part of the UTAevent class:

int fgetline(FILE *fp, char s[], int lim)
{
    // ...
}

Look at the other functions declared in UTAevent class, how are they defined in the .cpp file? What is the difference between those functions and your fgetline.

Salem commented: nice catch +21
thelamb 163 Posting Pro in Training

Look closely at my previous posts, I posted a code snippet there and asked you what you think would happen... you shouldn't just ignore that :P But here we go again:

int main()
{
     float myFloat = 0;
     {
          float myFloat2 = 5;
          myFloat = myFloat + myFloat2;
     }
     cout << "myFloat: " << myFloat << "\n";
     cout << "myFloat2: " << myFloat2 << "\n";
}

And another one to think about:

int main()
{
     float myFloat = 0;
     float myFloat2 = 3;
     {
          float myFloat2 = 5;
          myFloat = myFloat + myFloat2;
     }
     cout << "myFloat: " << myFloat << "\n";
     cout << "myFloat2: " << myFloat2 << "\n";
}

What do you think (without trying to run it) will be the output in the 2 cases?

thelamb 163 Posting Pro in Training

Don't you already do it with 'Equipment' ?

You have several options on how to store the Hero object in the vector, you can store it like you store the "String" in Equipment, or you can decide to store a pointer to a Hero object (Hero*) instead.. it depends on the requirements of the assignment what to chose.

I don't know the lvp library, but with the standard library the vector class has a member function "push_back" which allows you to add elements to the vector. (e.g. vHeroArray.push_back( new Hero() ); if you want to store hero pointers)

thelamb 163 Posting Pro in Training

Ok you need to understand 'locality' of a variable.

Your numberInputs is an argument to the function calculateAverage, correct? This means that when you call the calculateAverate function, you will hand over a value for the numberInputs, this value will then be available for use in the calculateAverage function.

I think it's best I write a small example:

int increase( int myInt )
{
    return myInt + 1;
}

int main()
{
    int myInt = 1;              // int variable that is avaiable to main.
    int mySecondInt;        // another int variable that is available to main.
    mySecondInt = increase( myInt );  // hand over the myInt from main to increase and store the result of the function in mySecondInt

}

Note how I am able to use a variable called 'myInt' in both the increase function and in main, the reason is that they are in completely different 'scopes'.

If you make a variable global however, it will be available to all functions:

int myGlobalInt;
void increaseGlobalInt()
{
    myGlobalInt++;
}

int main()
{
   myGlobalInt = 6;
   increaseGlobalInt();
}

Let's write up another example and see what you think will happen:

int main()
{
   int myFirstInt = 1;
   {
          int mySecondInt = 2;
          myFirstInt = myFirstInt + mySecondInt;
    }

   cout << "First int: " << myFirstInt << "\n";
   cout << "Second int: " << mySecondInt << "\n";
}
thelamb 163 Posting Pro in Training

I didn't look through your whole code, but what you do with the thread makes no sense.

You create the thread, and then wait for it to complete. Why is this needed? E.g. why did you chose to use a thread rather than just call the function directly.

Anyway.. to answer your question:

pthread_create(&thread1, NULL, (void*) cvWriteFrame(writer0, frame0) , NULL);	
pthread_join(thread1, NULL);

pthread_create expects a pointer to a function with prototype:
void *(__cdecl *)(void *)

This means it is a function that returns nothing(void) and takes one void* as argument.
So cvWriteFrame is not going to work directly with pthread_create because it takes 2 arguments, not 1. I guess this function comes from a library so you can't change it to only take one argument.

So... think about if you really need the thread, if you think you do... read up pthreads

thelamb 163 Posting Pro in Training

Absolutely not.. there is more wrong with declaring the variable on top than inside the for statement.

It's all to do with scope, if you declare the variable on top of the for loop, it is still in scope when the for loop exits, which is usually not what you want.

Declaring it in the for statement means the variable will go out of scope when the loop ends.

So declaring it on top, without using it anymore after the loop creates confusion for other people reading your code.

mrnutty commented: Exactly^2 +5
jonsca commented: Yes +4
thelamb 163 Posting Pro in Training

i is generally used for loop counters.. but no one is forcing you.
Specially if the body (the part between { and }) of the for loop is big, you might consider using a more meaningful name for the loop counter.

There are a lot of 'naming conventions'.. each with people who like it and people who protest it.

I generally use i if the body is small, else something like iLoopCount or simmilar. In any case... consider what your personal perference is and stick to it (be precise).
I personally have a strict naming convention.. e.g. pointers start with p, a 'char' starts with c, strings with sz, DWORDs with dw(or ul) etc.

thelamb 163 Posting Pro in Training

You are close actually.. it's really not that horrible.

Look at average in the .h file, and then at average in the .cpp file.
Now think of it from the compiler perspective, it sees int average( int something ); in the header file, so a function that takes an int and returns an int.

In the .cpp file, it finds int average( numbersInput ); here it has no idea what 'numbersInput' is.. and then in the function body you define numbersInput again by saying 'int numbersInput'.

So the way this works is you need to synchronize the header and the cpp file, except for the argument names, so for example:

.h file:
int average  ( int );
int average2( int thisIsAnIntVariable );
int average3( int myInt );
.cpp file:
int average ( int ) { return 4; }  // Illegal, don't know the name of the variable
int average( int myInt ) { return myInt; } // OK
int average2( int myInt ) { return myInt; } // OK (var names dont need to match)
int average3( double myDouble ) { return 4; } // ERROR

Hope that helped.

thelamb 163 Posting Pro in Training

You have bigger problems than this...

void main() <-- really?

char *delim = ";"; <-- You need to learn what a pointer is, and how to use them, what you do here should ring a million alarm bells.

The error you are getting is because you are trying to assign a _char pointer_ to a char.

jonsca commented: Yes +4