49,761 Topics
| |
I wrote two functions like that int absolute(int a) { return (a < 0) ? -a:a;} int absolute(int &a) { return (a = (a < 0) ? -a:a;} The two function have the same name and the same type, When I do like that: int main() { int a = … | |
I have studied functions, pointers, recursive(I suck at it though), file handling(slightly), loops and a bit of data structures. My final project of my semester is due very soon. I chose othello. Before I was able to succesfully make hangman. Now, this is my first time that I am trying … | |
Hello, after I have friendet my class to "<" operator it dosn't work after i use sort over an vector of class instances it does nothing: class + main : class RAngle{ public: int x,y,l; RAngle(){ } RAngle(int i,int j,int k){ x=i,y=j,l=k; } bool operator<(const RAngle& rhs)const { if(l < … | |
Someone looking at my code today told me that I didn't need to delete a pointer I declared in one place because I didn't create it using the "new" operator and went on to say that you only have to delete them when you use the "new" operator to declare … | |
Good Afternoon, I'm having problems with the termination of C++ program that deals with else if statements within a while loop. Below is the code that I have so far. while (choice != 'y') { //get the choice cout<<"What is your choice? ('a' to 'd', or 'A' to 'D') =>"<<endl; … | |
Why does the below crash? My pointer is still alive and is constructed in the main so it should not die until main returns :S I was using this with createthread a while back but my Mingw4.5 never supported it. I just upgraded to 4.7 but now this crashes and … | |
I have a problem. im trying to have it(it being this program ive writen), to when i press it, for example w for a piece of code to be preformed. My code is as follows. int loopprocess = 0; int score = 0; int keycomand = getch(); while (loopprocess == … | |
I think there are memory leak in my application, perhaps the problem is in a part of code status = myPubSubSubscribe.Receive(fsReceivedTopic, myBufferSubscribe, myHeader, 0); if (status == PS_ENGINE_UNAVAIL) { printf("Unable to connect to the pubsub engine: %s\n", PSPubSub::Status2String(status)); myBufferPublish.FreeBuffer(); myBufferPublish.~PSBuffer(); myPubSubPublish.~PSPubSub(); myBufferSubscribe.~PSBuffer(); myPubSubSubscribe.~PSPubSub(); return; } | |
So, I wrote this snake game in C++ using SFML 2.0 RC and everything was working perfectly until I tried to implement frame independent movement. I understand how to do it, but I can't seem to make it work with my snake game. If the SCALE define is set to … | |
I have a header file that I include into my main.cpp file. I want to set some flags when this file is included. std::cout.flags(std::ios::boolalpha); I want to set that automatically how can I do this? I tried: #ifdef DEFINES_HPP_INCLUDED std::cout.flags(std::ios::boolalpha); #endif //Gives me the error: //error: 'cout' in namespace 'std' … | |
Hello, I have a problem with c++ windows form. I read a number of elements from first textbox and from second I have to read a height of these elements (i.e. n=5, heights = 150, 160, 170, 180, 190). I made it first in console app and works perfect, but … | |
struct pieces { string ap, bp, cp, dp, ep, fp, gp, hp, ip, jp, lr, rr, lk, rk, lb, rb, q, k; } b, w; Code 1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C2146: syntax error : missing ';' before identifier 'ap' 1>c:\users\will\documents\visual studio 2010\projects\chess\chess\pieces.h(3): error C4430: missing type specifier - int assumed. … | |
I'm trying to understand recursion and stack overflows. First, why does this not cause a stack overflow? Is it because the function returns every time and that the stack isn't populated upon each call? void Meh() { } int main() { while (true) Meh(); } Two, What is the difference … | |
erm i learn new thing, its a bad idea to use "using directive" inside a class declaration, because this can leads to ambiguous functions/statements inside the main program. using namespace std; the question is, is it okay to use "using declaration" inside a class declaration? such as : using std::cout; … | |
I need to use forms, widgets etc. in my program which already takes care of creating a window and such. So the question is, would it be okay to use Windows lib to add the needed features, such as a form with a few widgets without any errors, memory leaks … | |
The code below gives me a Narrowing conversion from int to uint32_t: typedef union RGB { uint32_t Color; struct { unsigned char B, G, R, A; }; } *PRGB; inline RGB Rgb(int R, int G, int B) {RGB Result = {((R & 255) << 16) | ((G & 255) << … | |
// The Physics Game.cpp : Defines the entry point for the console application. //Rodney Jenkins #include "stdafx.h" #include <iostream> #include <cstdlib> #include <ctime> #include <cmath> using namespace std; double eqOne_vf(double Vi , double a , double t) { return ( Vi + (a * t) ); } double eqTwo_x(double Vf … | |
Hi, Im new to SDL, when i compile this example program i got these linker errors first defined here .drectve `/manifestdependency:"type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized [Linker error] undefined reference to `__security_cookie' [Linker error] undefined reference to `_alloca_probe_16' [Linker error] undefined reference to `@__security_check_cookie@4' [Linker error] undefined … | |
hi all this is the code in question namespace std { typedef std::basic_string<wchar_t> wstring; }; #endif #if defined(__HAIKU__) namespace std { class wstring : public std::basic_string<char> { public: wstring(const char *t) : std::basic_string<char>(t) { } wstring() { } wstring(const wstring &that) : std::basic_string<char>(that.c_str()) { } wstring(const std::basic_string<char> &that) : std::basic_string<char>(that) … | |
Hi, I just to know what code should I use to terminate the program when the user input the character n. Here is the code I have so far | |
To be specific I'm trying to implement this into a small game. What I'm thinking of is having a base/default class for derived objects such as player, enemies, tiles and so on and later the derived classes would inherit this base class and add whatever is needed depending on the … | |
Hello All! I was just wondering if C++ classes could internally be represented in the following way: #include <stdio.h> struct A { int a; void (*ptr) (A *); }; void display(A *ptr) { ptr->a = 2; printf("ptr->a = %d", ptr->a); } int main() { A obj; obj.ptr = display; obj.ptr(&obj); … | |
Hello everybody, I'm in need of a bit of help here. I got this C# snippet: public static byte[] StringToByteArray(String hex) { int NumberChars = hex.Length; byte[] bytes = new byte[NumberChars / 2]; for (int i = 0; i < NumberChars; i += 2) bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), … | |
excuse me but can someone teach me how to get a string with space example : this author i need to get the codes on how to get that thank you | |
hi, i read in ebook about overleaded iostream operator for class, but im a bit confused about this one : ostream &operator << (ostream &strm, const FeetInches &obj) { strm << obj.feet << " feet, " << obj.inches << " inches"; return strm; } > Notice the function has two … | |
I currently have a running program. All i want to do is be able to shut it down at anypoint by pressing CTRL C. I cannot figure out the code for this command for the life of me. Can someone please help me out? thank you. I am using c++ … | |
**Dudearoo** *Useing Code::Blocks* Hey you guys. ive got a problem, ive got a simple while loop being executed that loops 41 lines of code untill the user types no for example int repeat = 2; while (repeat == 2) { // my code // || Example Code // \/ cout … | |
Good Afternoon, I'm new to C++ programming and I have to do a program that deals with strings. Below is the code that I have so far, I have problems in this section of the program Get three lines from the keyboards. Play with string copying, concatenation, and input size … | |
Hi I need the answers one of my two questions which were asked by our teacher in class room. Q1. Languagess are system software or application software? Q2. In which software the languages are written? for example in which software the c++ language is written? plz give your answer with … | |
hi everyone I am having a little problem with the program below. If I input "2/5 * 2/6" the char "/6" will be stored, so when I try to multiply by a simple variable by entering "3/7 * 6" the program will read "3/7 * 6/6". is there a way … |
The End.