CoolGamer48 65 Posting Pro in Training

@williamhemswort
namespaces shouldn't end with a semicolon (though AD didn't point that out so I'm not sure I'm right about that...). I also don't think non const variables can be defined outside a function, though I could be wrong about that as well. Not sure what's wrong with the using statements.

edit: Checked cplusplus.com - right about no semi-colon, wrong about initializing non-consts.

CoolGamer48 65 Posting Pro in Training

Well, I don't agree with this. The streams are declared friends of the class Nibble so they should have the right to access private data. Here's the modified code, where the union yields a variable that simply holds an int--

Oh, right. At a glance I thought they were method declarations, not prototypes for global functions.

CoolGamer48 65 Posting Pro in Training

Post the errors and a description of your problem/question.

edit: Sorry, didn't see the comments in your code. Still good to post a description of the issue though.

I see a couple of strange things, but the one related to your union:

union
{
int number : 4;
};

What are you trying to do with the colon? Also, I don't believe there's a point to a union with only one element.

I think the error may be caused because the overloaded operator you're defining is a global function, and it's trying to access a private member of a nibble.

CoolGamer48 65 Posting Pro in Training

1. You didn't listen to one of the above posters. Don't do this:

cin >> name;

If I type a name that's larger than 20 characters your program will crash.

2. Unless this is for a class and your instructor says you must use character arrays, use std::strings. They're so much easier to work with.

3. Are you sure the output in the image came from the program above? Nothing in the program should cause "Press any key to continue" to appear (unless it's something to do with stdafx.h, of which I know little).

CoolGamer48 65 Posting Pro in Training

i think instead of directly assigning one string to another u should use strcpy function..try it...

Kind of off topic, but strcpy() is meant for use with C-Strings (i.e., char*). When using std::strings (which you should :) )you use the (overloaded? ) assignment operator.

CoolGamer48 65 Posting Pro in Training

I don't understand why it says assigning either. If it said casting or converting or something like that then I would get it. Because true really isn't of type int, it's of type enum bool, so when comparing it to an int there has to be an implicit cast or conversion, which is probably what the warning is about.

CoolGamer48 65 Posting Pro in Training

Moral#2: Never, never use bool, true and false identifiers in your C++ programs, even if you have a very old compiler...

Wait - you're saying to not use variables of type bool?

CoolGamer48 65 Posting Pro in Training

the string::c_str() method converts the contents of an std::string to const char*. For example:

string str1 = "Hello";
const char* str2 = "Hello";
str1.c_str();//would return a value equivalent to str2

further information here

You'd be better off using string streams though. there isn't a need to convert an std::string into an old C-string (const char*). string streams can handle std::strings and C-strings.

Salem commented: Say yes to string streams, no to atoi +20
CoolGamer48 65 Posting Pro in Training

Always post the exact errors you get for the best help.

atio() takes input of type const char* .

do this:

x=atoi(str.c_str());

Or, better yet, use stringstreams:

#include <sstream>
using namespace std;

int main()
{
    stringstream ss;
    int x;
    string str = "34";
    ss << str;
    ss >> x;

    return 0;
}
CoolGamer48 65 Posting Pro in Training

This: module = new MyClass(true); line should not work in either case. module is of type MyClass, but new MyClass(true) is of type MyClass*. That assignment shouldn't work - are you sure the latter example compiles?

Also, use [code]

[/code] tags, not [quote][/quote] tags.

CoolGamer48 65 Posting Pro in Training

( x || y ) is an expression of type bool (at least I think so - even though you can't declare variables of type bool it still exists as a type) true is of type int. I believe this comparisan of int to bool is causing the issue (though the error you gave would suggest otherwise, since there is no assignment in the example above)

simply remove the == true. It's unnecessary, not just in this case but in all cases. (x || y) is already of type bool. there is no need to add the == to make it a bool.

CoolGamer48 65 Posting Pro in Training

*sigh*

Okay, you want to know where to start. I've never written an AVI loader - but here are a couple of places to start (and I don't think where you start is going to be language specific).

  • Learn how to make a GUI. I gave you a link for a starting tutorial for the windows API. If you've got access to MFC (which I believe is just a wrapper for the API), then use that. Don't want to use the API? How about DirectX? A bit more complicated but you can make the GUI look like whatever you like. Rather use something a little more open source? OpenGL (same scenario as DirectX). You're not on Windows? What OS are you on? OpenGL still applies, but there may be other options. So, go out to Google, and try to make a GUI. If you run into specific problems, come back and tell us. Some examples: Can you guys show me the basic structure of a Windows application using the Windows API? better yet: I wrote this GUI (post the code) and it won't compile. Here are the errors: <errors here>. How can I fix it?
  • Learn to interface with SQL. Just Google it. You should get some APIs and tutorials for whatever language you want. Those should help you. If you then have specific questions about that, post them.
  • Learn to load an AVI file. This is a bit more difficult. I gave you link in my previous …
CoolGamer48 65 Posting Pro in Training

Do you need us to lay out the steps of what you need to do? I thought you had already planned that? You want to know how to make a Windows looking GUI? Windows API or MFC, if you've bought it. Here's a quick tut on the API, don't know much about MFC. Do you want to know how to how to load an AVI file? A site I was referred to on this forum. Want to know how to interface with SQL databses? Google is your friend.

If thats all your forum has for me then I'll leave, disappointed.

This isn't a substitute for a search engine. You've given us a complex program, and are asking us what you should do. You've laid out the basics of what you want - decide to work on one of the components of your program and go look some stuff up. If you have more specific questions then, ask them. But unless someone has recently worked on an AVI loader that does the things you want and doesn't mind sharing, no one is going to go out and make one just to give you an idea of where to start.

CoolGamer48 65 Posting Pro in Training

Simple - because I must.

You must? Was it assigned to you for your job or something? I don't have any industry experience, but I'm pretty sure a decent boss wouldn't give a huge project like this to a single person with limited programming experience.

VernonDozier's suggestion of breaking up the program is smart - but you're going to have to do so much learning each step it might even be faster to just put the whole idea of your current project aside now, and work on getting the basics down.

CoolGamer48 65 Posting Pro in Training

@second error
you wrote itsVectorOfNotebook in one or more places (one of which is line 135 of CTesterClass.cpp) where you should have written itsVectorOfNotebooks .

Could you specify which line is 68 in CTestClass.cpp? The line numbers are different since you bundled .h and .cpp files.

CoolGamer48 65 Posting Pro in Training

The only insert function of the vector template I found takes two parameters - one of type size_t, and the other of type Item_type. When you call it, you're only specifying the Item_type parameter.

Also, I believe the entire purpose of the VectorOfNotebooks class is to not have to use the template directly. There is no added functionality. Use typdefs instead.

typedef CVectorTemplate<CNotebook> VectorOfNotebooks;
CoolGamer48 65 Posting Pro in Training

Thank you!
But, tell me please, in the first method why the blank character (the space) is omited by default?
Is there one error, or such work the method?

The extraction operator >> skips over whitespace. To read a file character by character including whitespace, use the get() method. Though I would just listen to Ancient Dragon.

CoolGamer48 65 Posting Pro in Training

It means that strncpy is old and/or something better is around to use instead of it.

CoolGamer48 65 Posting Pro in Training

I tried everything and none of them worked on my friend's computers. :( Most commonly they said to download Visual C++ 2008 Redistributable package, but I'm using Visual C++ 2008 Express. Any suggestions?

It doesn't matter if you're using Express. I had to do the same thing.

CoolGamer48 65 Posting Pro in Training

I myself have run into problems with side by side configuration, and while I don't fully understand it, it is not an issue with Vista. I've run into the same problem when moving an app from one xp machine to another.

CoolGamer48 65 Posting Pro in Training
int converter(int x, int y)
{
    if(y == 0)
        return 0;//or -1, or whatever you want to happen instead of a divide by zero	
    return x / y;
}

You could use backspace to get rid of the old text:

for(int i = 0;i < numChars;i++)
    cout << "\b";

numChars is the number of characters you output.

There's a clear command on the Linux kernel that clears the prompt of text. I don't know if there's a Windows equivalent, but you could call it with system();

CoolGamer48 65 Posting Pro in Training

You might want to also add a check in converter() (or somewhere else) to make sure that the number of deaths is not 0.

CoolGamer48 65 Posting Pro in Training

It isn't bogus crap. Learn to understand it and you'll begin to be able to solve problems on your own, though its understandable that at first you'll have no idea what it means.

The compilers complaining that the function PlaySound is declared somewhere, but it has no implementation. I'm actually not sure why it said it twice. The implementation would either be in the form of a .cpp file, or, in this case, a .lib file.

To fix this you need to link to the .lib winmm.lib. A simple way to do this is to add

#pragma comment(lib,"winmm.lib")

in one of your source files.

Wiki_Tiki commented: Helped well with 2 fatal compiler errors +1
CoolGamer48 65 Posting Pro in Training

scratch this - didn't see the second page

btw, how do you get the code tag to come up properly without it thinking it's an actual code tag?

CoolGamer48 65 Posting Pro in Training

It has to do with the way your compiler is interpreting strings (I think it happens when you set the character encoding to unicode instead of multibyte, or something like that).

I think that this:

PlaySound((LPCWSTR)"beep.wav", 0, SND_LOOP|SND_ASYNC);

will work.

CoolGamer48 65 Posting Pro in Training

Salem meant you should wrap your code in code tags (the (code) button on the top, or just type YOUR CODE HERE, with four spaces before code).

Do you want the for loop to be part of this conditional:

else if ((peso > 30) && (peso < 1000) && (dia = 9))
cout << " Se le cobraran 15$ " << "\n";
//for loop only executed if peso is between 30 and 1000 and dia is 9

If so, just wrap the code in curly brackets:

else if ((peso > 30) && (peso < 1000) && (dia = 9))
{
    cout << " Se le cobraran 15$ " << "\n";
    for(;;)
    //your loop here
}
//next else if condition

If you meant that the loop is executed regardless of the above conditional, you can also do that, though the else if after it would need to become a regular if:

/*else*/if((peso > 1000) && (dia = 7))
CoolGamer48 65 Posting Pro in Training

I type in Pizza.

That won't work. The symbol Pizza is only defined in your program to mean 10. When you type in "Pizza" at the console, it's interpreting it as a char* (I think), and I don't know how that translates to an integral type, but it won't be 10. You need to actually type in the number 10, or interpret the string "Pizza" and realize that it means 10.

CoolGamer48 65 Posting Pro in Training

When you run the program, and you want to guess that your favorite food is pizza, do actually type in "pizza", or do you input 10?

CoolGamer48 65 Posting Pro in Training

To address your first issue: void pointers. Google it. It's basically a pointer that has no type bound to it. I haven't used them too much but I think they fit your needs.

Your second problem:
You can check to see if there is data to be read. Use the empty() method of the vector class to see if it is empty or not. As for arrays, if you initialize the array of pointers to NULL, rather than having bad pointers. Then you can do

if(passengers[i])
//output data
CoolGamer48 65 Posting Pro in Training

Google is very nice:
link

As others have said, post code, but this, or something like it, would cause the problem you're having:

void Func()
{
    cout << "I am a function.\n";
}

int main()
{
    if(Func())//Func() returns nothing - you can't check if a nonexistent result is true or false
        cout << "Helllo.\n";

    return 0;
}
CoolGamer48 65 Posting Pro in Training

C++ is a language, as defined by ISO.
Visual C++ is an implementation (like Borland, GNU, Intel).

Any modern 32-bit compiler will probably meet your needs for learning C++.

Wait, so every compiler is considered to have it's own "implementation" of C++? So, is it possible to have a compiler that compiles pure C++, or is pure C++ just a language on paper?

Or did you just mean that Visual C++ implements the C++ language?

CoolGamer48 65 Posting Pro in Training

scratch this

CoolGamer48 65 Posting Pro in Training

exp *= exp when exp is 1 means exp *= 1; , exp = exp*1; , exp = exp; . That increment does nothing. To increase exp by 1 every iteration, do exp += 1; , if that's what you meant. Also, what is exponente? What is it set to?

CoolGamer48 65 Posting Pro in Training

Why are you doing this->Close(); ? You can just say Close(); if you're within the scope of the function, can't you? (unless you're trying to specify that you're not referring to some external Close() function, but I don't see how the compiler would think you mean that over a member of the class).

CoolGamer48 65 Posting Pro in Training

If you're on windows, a common way to do it is system("PAUSE"); . It gives a prompt like "Press any key to continue..."

CoolGamer48 65 Posting Pro in Training

Couldn't he also use pointers?

if( TTF_Init() < 0 )
   {
	   return 1;
   }

     Font* thing = new Font;
     delete thing;

   TTF_Quit();
CoolGamer48 65 Posting Pro in Training

error C2511: 'Contributor::Contributor(std::string,double,Contributor::gender,int)' : overloaded member function not found in 'Contributor'
see declaration of 'Contributor'

Can't say I'm 100% sure - but after looking at it a bit I'm pretty sure:

You have two enumerations. The first is gender, which is declared and defined in global scope. The second is Contributor::gender, which is declared as a private member of the Contributor class. When you declare the constructor we're dealing with in the .h file, one of it's types is gender, and since we're in the scope of Contributor, it is assumed that gender refers to Contributor::gender. However, when you define the constructor in the .cpp file, you say gender once again, only this time, you're referring to the global gender enumeration (since we're in global scope), and so the compiler complains that you're defining an overloaded method with different parameter types than any of the ones in the class declaration.

I'm assuming you only wanted one enumeration. Take the line that first declares gender (outside of the class), and move it to the top of the .cpp file, and change it from enum gender ... to enum Contributor::gender...

CoolGamer48 65 Posting Pro in Training

Err, what exactly is the error you get? From what line?

CoolGamer48 65 Posting Pro in Training

well i tried to do something like that with the standard headers, and wouldn't compile. And when i changed the order, it worked. also is it the same for all OS's, i wanna port my apps to linux too, and include python.

What errors did you get? What was the wrong order and what was the order that worked?

CoolGamer48 65 Posting Pro in Training

If you'd like to link to a lib through the compiler's interface rather than using #pragma, right-click on your project's name in the panel to the left, go down to properties, expand linker, go to input, and put the libraries names in the additional dependencies field, separated by spaces.

guy40az commented: thanks again !!! +2
CoolGamer48 65 Posting Pro in Training

I learned C++ from C++ for Dummies. I enjoyed it, but I've heard bad things about it because it has typos. I did notice a couple of typos when going through it, but it was nothing I couldn't bare or make sense of.

Still, there may be better books out there.

CoolGamer48 65 Posting Pro in Training

Do you know about templates? You could create a Linked List template class to make things easier to understand. Though, on second thought, creating a linked list template class can be a hassle, and giving you one wouldn't teach you anything about linked lists.

CoolGamer48 65 Posting Pro in Training

Well why do you have a return in the function, you shouldn't need one because you are passing back by reference.

Wait, I'm not sure if he edited the code in the first post, but the function just had return; , not return someVal; . It's not neccesary to include the return; statement at the end of a void function, but I sometimes put it just so I'm controlling when the function returns, not the end curly bracket. Is that considered "wrong" or weird?

CoolGamer48 65 Posting Pro in Training

> So if the code file1.h needs to be executed before the code in file2.h (for some reason)
But compiling is not executing. #include is all about declarations, not program execution order. In other words, this works.

#include "func1.h"
#include "func2.h"
int main ( ) {
  func2();
  func1();
}

Ya - I thought I had used the wrong word.

CoolGamer48 65 Posting Pro in Training

The code in header files is executed in the order you #include them. So if the code file1.h needs to be executed before the code in file2.h (for some reason), then they must be #included in that order.

CoolGamer48 65 Posting Pro in Training

Er, there seem to be some awfully large gaps in your basic C++ knowledge to be writing a game.

File I/O is the first thing you typically learn how to do.

It wasn't for me.

Alright thanks, but what directive do you use to use ofstream and ifstream? If their stats are increasing as they progress through the game, how do you write it to the save file when they tell it to?

The code I showed you

1.
      ofstream fout("file.sav");
   2.
      fout << health << "\n" << mana << "\n" << etc;

is all you need to write the variables health, mana, and etc to a file. If you want to add more/different variables (im assuming you do), just add them following the above pattern. Make sure to #include <fstream> at the top of your file.

CoolGamer48 65 Posting Pro in Training

You would use ifstream to read data (much like cin), and ofstream to write it (like cout). (note: cout and cin are objects of classes that are already made. ifstream and ofstream are actual classes).

To write data:

ofstream fout("file.sav");
fout << health << "\n" << mana << "\n" << etc;

to read data:

ifstream fin("file.sav");
fin >> health >> mana >> etc;
CoolGamer48 65 Posting Pro in Training

Say you have a file like this:
file.txt
45
hello
4

You could read and display the data like this:

ifstream fin("file.txt");
int x, y;
string str;

fin >> x >> str >> y;
fin.close()

cout << x << "\n" << y << "\n" << str << "\n";

This would output:
45
4
hello

CoolGamer48 65 Posting Pro in Training
tempatures = "file.txt";

This will output to the file "file.txt" (it will be created if it isn't already - thought i'm not sure if ios::app changes that behavior).

But this variable is unnecceasry. You could simply do:

ofstream tempature("file.txt", ios::app);

And get rid of the variable tempatures.

CoolGamer48 65 Posting Pro in Training

The c-string temperatures is declared char *tempatures; , but never intialized. Then you try to use it in the constructor for temperature ofstream tempature(tempatures, ios::app); . You need to tell the compiler what file to open.