- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 2
- Posts with Upvotes
- 1
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
23 Posted Topics
I've been messing around with c++ and attempting to fully understand certain behaviors. Given the following program: [code=C++]#include <iostream> class Test { public: Test(); ~Test(); void func(); }; Test::Test() { std::cout << "Constructor" << std::endl; } Test::~Test() { std::cout << "Destructor" << std::endl; } void Test::func() { std::cout << "Deleting … | |
Re: 'Char' is not a valid C++ type. 'Num' function does not match its prototype (see lines 23 and 58). 'Num', if ever executed, will never execute lines 66-77; enclose your 'if' statements in braces and you should find the answer. Match all opening braces ( '{' ) with closing braces … | |
Re: When you add the semicolon, that is the scope of the loop. [icode]while (true) {this stuff executes} [/icode] [icode]while (true); {this stuff never executes}[/icode] The semi-colon is terminating the scope of the loop before it executes the stuff inside the braces. The same applies for 'if' and 'for'. | |
Re: Try changing SDL_SURFACE to SDL_Surface. Also, for ease of use, you might try dumping the SDL headers into your IDE's header folder - a wee easier than typing that long string per source file. | |
Re: Try re-examining the flow of your program. Think as the compiler: go line by line and ask "What is happening here?" If you do not understand something in your code, I recommend you look it up on [url]www.cplusplus.com[/url] | |
Re: sqrt() requires a double, float, or long double as a parameter. Judging by your variable name, you're attempting to pass an int to sqrt(). Try using static_cast to convert it to a double like so: [code=C++]cout << "The square root of " << num << " is " << sqrt(static_cast<double>(num)) … | |
I'm having several difficulties with memory leaks in a program (I've been using "Visual Leak Detector" to check for memory leaks). I've simplified the code to the following: [code=C++]#include "vld.h" #include "vldapi.h" #include <string> #include <vector> class BaseFoo { public: BaseFoo() {} ~BaseFoo() {} }; class ButtonFoo { public: void … | |
Re: Rather than having YesorNofunc() call another function, it would probably be easier to have it return int. You could declare two constants (or use #define) YES and NO. Then whenever you need a yes or no answer, you could use an if/else statement: [code=c++] const int YES = 1; const … | |
Re: Under "Build", click "Build Solution", or just hit F7. If there is no "Build" in the menu, then you need to create a project first. Click File->New->Project. | |
Re: [quote=Read This Before Posting]Keep the code short and sweet! As much as we don't care, people insist on posting pages and pages of irrelevant code. Keep the code as short as possible. If the code isn't short, make it short by cutting out as much irrelevant code as possible. Ideally, … | |
Re: Your problem with the "ambiguous overload for operator in cin >> variable" is caused because variable was declared as const. When you declare something as a const, it [U]cannot be changed[/U]. Since a const variable cannot be changed, cin cannot write any data to it. You'll also have a problem … | |
Re: You don't need to declare Q and q as chars to use 'Q' and 'q'. You also have an unreferenced variable (ie, a variable you declared but never used). Take a closer look at the logic in the while loop. It won't execute as you intended. It will always be … | |
As I was busy inlining some of my functions, I was wondering if it is really necessary to inline anything. Doesn't the compiler automatically inline stuff, or do I have false memories? And if the compiler does inline stuff for me, would it be best to let it do its … | |
Re: I think the problem is with the constructor. You either need to add parameters matching the class constructor in the line [icode]Mortgage myMortgage();[/icode] or make a default constructor with no parameters. It's the same problem as this: [code=C++]#include <iostream> using namespace std; class MyClass { public: MyClass( int a ); … | |
Re: [QUOTE=yu83thang;710009] Below is my declaration a Class in window form application, and the error was stated as below: CLoadObj^ g_LoadObj = gcnew CLoadObj; [/QUOTE] I believe you mean CLoadObj* g_LoadObj = gcnew CLoadObj; | |
Re: Remove [icode]#include "stdafx.h"[/icode]. | |
I have a vector array of a class that's giving me some crap. I would beat it up, but that might result in some innocent circuits getting damaged. Class: [code=c++]class Font { public: Font(); ~Font(); int style; int ptSize; std::string name; TTF_Font *font; }; Font::Font() { style = TTF_STYLE_NORMAL; ptSize … | |
Re: For file operations, look up the [URL="http://www.cplusplus.com/reference/iostream/fstream/"]fstream[/URL] header. The basic code looks something like this: [code=c++]#include <fstream> using namespace std; int main() { fstream file; file.open( "whatever.whatever" ); // Check to make sure the file is open with file.is_open() // Read data line by line using file.getline(); works just like … | |
Re: The easiest would probably be Simple Directmedia Layer, found here: [url]http://www.libsdl.org/[/url] | |
I'm creating a multiplayer game using winsock, but I've been having several problems with winsock. I've been searching for an alternative to it, but I haven't found anything. If anyone could point me to something I could use in place of winsock (a free something), I would greatly appreciate it. | |
I've been getting an "Access Violation" error while running this program: [code=c++]#include "SDL/SDL_ttf.h" class Font { private: TTF_Font *font; public: Font() { font = TTF_OpenFont( "c:\\windows\\fonts\\cour.ttf", 20 ); } ~Font() { TTF_CloseFont( font ); //Access violation } }; int main( int argc, char *args[] ) { if( TTF_Init() < 0 … | |
I have a header file causing me several errors. It contains a class definition, then I have a *.cpp file with the function definitions. Header: [CODE]#ifndef DOT_H #define DOT_H #include "SDL/SDL.h" #include <vector> class Dot { private: int x, y; int xVel, yVel; vector<SDL_Rect> box; bool check_collision( vector<SDL_Rect> &A, vector<SDL_Rect> … | |
I have a function which takes an array of SDL_Rect (which is a data structure containing four integers, x, y, h and w), and assigns values to the data members. However, when I try to compile, each line generates the error "error C2059: syntax error : '='". [CODE] int main() … |
The End.