• What do you need help with? Version 1
    5,001 replies, posted
I never define more variables on one line. I always do this: [code]int a; int b; int c;[/code] I usually place * with the type. Makes more sense to me, as it describes the type.
[QUOTE=Drak_Thing;25285921]I just started messing with C++, and I wanted to make a class that will handle files, such as loading/logging stuff with SFML. Would this be the right way to go about it? [code] #include "FileHandling.h" #include "time.h" CFileHandler::CFileHandler() { char dateStr[9],fileName[128]; _strdate( dateStr ); sprintf(fileName,"Log_%s.log",dateStr); printf("Name: %s",fileName); pFile = fopen( FileName, "w+" ); if( pFile != NULL ) fclose(pFile); // We now will re-open the file (since it's created) // And append to it. pFile = fopen( fileName, "a+" ); } CFileHandler::~CFileHandler() { if( pFile != NULL ) fclose(pFile); } bool CFileHandler::UTIL_FILE_Log( int enumLog, const char Char[256] ) { fputs( Char, pFile ); return true; } [/code] Then use the class "CFileHandler myFiles" etc. Also, does anybody know how to replace letter's inside a char? OR convert a char to a string? Since "fopen" takes a char.[/QUOTE] Personally I would pass the filename to CFileHandler and then setup a CFileLog class which could auto fill out the filename.
[QUOTE=Richy19;25287739]i think i will use int *ptr its easier for me to think "the value of ptr is an int" also as you said earlier it looks better when you put int *ptr1, *ptr2, *ptr3;[/QUOTE] The only problem with this is that you might later confuse the pointer declaration asterisk with the pointer dereference asterisk. [code]int* ptr1; // * is part of type declaration int* ptr2; int num; ptr1 = ptr2; // assign ptr2 to ptr1 num = *ptr2; // dereference ptr2 and assign the content to num [/code] If * were part of the variable name, only the second assignment would be valid. Of course, this is all a matter of style.
[QUOTE=shill le 2nd;25291207]The only problem with this is that you might later confuse the pointer declaration asterisk with the pointer dereference asterisk.[/QUOTE] I use the asterisk attached to the variable and I never confused it with dereferencing.
Has anyone had experience with the Skype API? Is it normal for the MessageStatus event in C# to give me 2 of the same message?
Whats a good .net library for evaluating javascript?
iunno, but Google is a good tool to find a good .net library for evaluating javascript - if one exists.
It's possible to write a .NET wrapper for V8, as seen [url=http://stackoverflow.com/questions/356948/referencing-googles-v8-engine-from-a-net-app]here[/url].
How would I generate texture coordinates for a 2D polygon? So far I've been usin gglTexGeni: [cpp] glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); [/cpp] But all I see on the shapes is a general color from the image I'm trying to apply.
I'm having a problem with TrueBASIC. I wrote a program for school (riveting stuff) and it is meant to ask you questions by calling questions and answers from a DATA statement. After my computing teacher (the JPEG HAS 256 COLORZ one) started at it for 2 periods she didn't know what was wrong. Do any of you know what is up with this? code: [cpp] CALL initalise CALL inform_user DO CALL read_in_data CALL ask_questions LOOP until end data CALL Print_results SUB initalise LET no_correct=0 LET no_incorrect=0 END SUB SUB inform_user PRINT "This program will print out some questions" PRINT "all read from data statements and keep a" PRINT "count of how many the user got right" END SUB SUB read_in_data READ country$ READ capital$ END SUB SUB ask_questions PRINT "What is the answer of ";country$ PRINT INPUT answer$ IF UCASE$(answer$)=UCASE$(capital$)Then LET no_correct=no_correct+l END IF END SUB SUB print_results CLEAR PRINT "You got ";no_correct; "correct" END SUB DATA 4+5, 9, 21-9, 12, 354+40, 394, 41+90, 131, 1+5, 6 END [/cpp]
It helps if you tell us what is wrong.
Why is this not working? [code]class Fate::IClient * __stdcall GetClientInterface(class Fate::IEngine *)[/code] Here is the Client.cpp Snip: [code] extern "C" __declspec(dllexport) IClient* FATE_API GetClientInterface(IEngine *EngineInterface) [/code] This is the engine's WinMain.cpp Snip: [code] pClientGetInterface = (Fate::IClient* (FATE_API*)(Fate::IEngine*))GetProcAddress(hClientDLL, "GetClientInterface"); [/code] I'm waiting for a simple response from Overv or Turb
Silly me, yes in my BASIC program I answer them all correctly and it says 'You got 0 right'
[QUOTE=jA_cOp;25270300]Writing code in Perl looks painful.[/QUOTE] Right now at college I'm in a Perl course AND a COBOL course... (although the Perl course actually switches to PHP halfway through the semester)
[QUOTE=DevBug;25308774]I'm waiting for a simple response from Overv or Turb[/QUOTE] Sorry man, I'm no good with this stuff.
[QUOTE=turb__;25310042]Sorry man, I'm no good with this stuff.[/QUOTE] I am disappoint.
Snip, didn't realize this was the Programming section :downs:
so my friends and I decided to start up a robotics club (we did some robotics stuff last year, but not under a school club) and we're planning on making a remote-controlled blimp. One of my friend's dad makes night vision goggles for a living, so naturally this friend knows his way around electronics. He already blueprinted and ordered a prototype of a board that contains a GPS chip and has the ability to transmit data wirelessly. Right now he's writing the code for it in C, but is complaining about the method of user input being complete crap (apparently there was some base code that goes along with the hardware), so I thought it would be a good idea to write the GUI/input controls in a higher level language (I was thinking C#) and hook into the C program. What's the best way of hooking into another process/how would I get the two programs to interact? (It could send a command to move forward from a button and return the new GPS coordinates to a label or something like that...)
[QUOTE=robmaister12;25311078]so my friends and I decided to start up a robotics club (we did some robotics stuff last year, but not under a school club) and we're planning on making a remote-controlled blimp. One of my friend's dad makes night vision goggles for a living, so naturally this friend knows his way around electronics. He already blueprinted and ordered a prototype of a board that contains a GPS chip and has the ability to transmit data wirelessly. Right now he's writing the code for it in C, but is complaining about the method of user input being complete crap (apparently there was some base code that goes along with the hardware), so I thought it would be a good idea to write the GUI/input controls in a higher level language (I was thinking C#) and hook into the C program. What's the best way of hooking into another process/how would I get the two programs to interact? (It could send a command to move forward from a button and return the new GPS coordinates to a label or something like that...)[/QUOTE] Wrappers.
[QUOTE=DevBug;25311409]Wrappers.[/QUOTE] Thanks, after just a quick google it looks exactly like what I was asking for. I'll look into it a bit more...
[QUOTE=DevBug;25308774]Why is this not working? [code]class Fate::IClient * __stdcall GetClientInterface(class Fate::IEngine *)[/code] Here is the Client.cpp Snip: [code] extern "C" __declspec(dllexport) IClient* FATE_API GetClientInterface(IEngine *EngineInterface) [/code] This is the engine's WinMain.cpp Snip: [code] pClientGetInterface = (Fate::IClient* (FATE_API*)(Fate::IEngine*))GetProcAddress(hClientDLL, "GetClientInterface"); [/code] I'm waiting for a simple response from Overv or Turb[/QUOTE] reinterpret_cast :| What's the code in the uppermost tags? And what's not working? Getting an invalid handle? You could also do [cpp]#ifdef BUILD_LIBRARY #define LIBRARY_API __declspec(dllexport) #else #define LIBRARY_API __declspec(dllimport) #endif LIBRARY_API Fate::IClient * FATE_API GetClientInterface(Fate::IEngine *);[/cpp]
[QUOTE=ZeekyHBomb;25312856]reinterpret_cast :| What's the code in the uppermost tags? And what's not working? Getting an invalid handle? You could also do [cpp]#ifdef BUILD_LIBRARY #define LIBRARY_API __declspec(dllexport) #else #define LIBRARY_API __declspec(dllimport) #endif LIBRARY_API Fate::IClient * FATE_API GetClientInterface(Fate::IEngine *);[/cpp][/QUOTE] The uppermost tag is what dllexp shows. And yes, I can't get the handle of GetClientInterface.
[QUOTE=DevBug;25308774]Why is this not working? [code]class Fate::IClient * __stdcall GetClientInterface(class Fate::IEngine *)[/code] Here is the Client.cpp Snip: [code] extern "C" __declspec(dllexport) IClient* FATE_API GetClientInterface(IEngine *EngineInterface) [/code] This is the engine's WinMain.cpp Snip: [code] pClientGetInterface = (Fate::IClient* (FATE_API*)(Fate::IEngine*))GetProcAddress(hClientDLL, "GetClientInterface"); [/code] I'm waiting for a simple response from Overv or Turb[/QUOTE] DLLExp wouldn't be able to read all that information from the exported symbol if extern "C" had really been working there - it'd just be "GetClientInterface". And if it was, GetProcAddress wouldn't return null on you. First I'd try without stdcall, I think it's possible they get decorated with a minimum amount of parameter info - an "@" follows the function name, followed by the total amount of bytes required for the parameters. Otherwise, just because it will show you a more descriptive error on failure, try using a .def file instead: [code] LIBRARY "YourLibrary" EXPORTS GetClientInterface [/code]
[QUOTE=DevBug;25308774]Why is this not working? [code]class Fate::IClient * __stdcall GetClientInterface(class Fate::IEngine *)[/code] Here is the Client.cpp Snip: [code] extern "C" __declspec(dllexport) IClient* FATE_API GetClientInterface(IEngine *EngineInterface) [/code] This is the engine's WinMain.cpp Snip: [code] pClientGetInterface = (Fate::IClient* (FATE_API*)(Fate::IEngine*))GetProcAddress(hClientDLL, "GetClientInterface"); [/code] I'm waiting for a simple response from Overv or Turb[/QUOTE] Why are you hooking the source engine? At least thats what the interface looks like.
-snip- double post
I have a small problem with 2d vectors I used to initialize them in visual studio 2008 like this and it worked fine. [cpp]std::vector<std::vector<char>> levelvector ( 160, std::vector<char>( 480, 0 ));[/cpp] But in visual studio 2010 it gives me these errors on that line [code] error C2059: syntax error : 'constant' error C2059: syntax error : ')' error C2143: syntax error : missing ')' before ';'[/code]
[QUOTE=ColdFusion;25315340]I have a small problem with 2d vectors I used to initialize them in visual studio 2008 like this and it worked fine. [cpp]std::vector<std::vector<char>> levelvector ( 160, std::vector<char>( 480, 0 ));[/cpp] But in visual studio 2010 it gives me these errors on that line [code] error C2059: syntax error : 'constant' error C2059: syntax error : ')' error C2143: syntax error : missing ')' before ';'[/code][/QUOTE] As stupid as it sounds, you need a space to separate the two '>' tokens: [code]std::vector<std::vector<char[highlight]> >[/highlight] levelvector ( 160, std::vector<char>( 480, 0 ));[/code] Welcome to C++ :sigh:
Is that a part of the standard or just a compiler thing?
Changes nothing. Still the same errors.
[QUOTE=Darwin226;25315449]Is that a part of the standard or just a compiler thing?[/QUOTE] It's part of the standard. C++ is a stupid, complex piece of shit when it comes down to it. Get used to it. [/rant] [QUOTE=ColdFusion;25315474]Changes nothing. Still the same errors.[/QUOTE] It works fine here once I insert the required space, using GCC 4.5. MSVC might let you leave it out (you mentioned it used to work in VS05) since MSVC generally isn't very standard compliant. Make sure the error is actually generated by that line. MSVC is terrible with error messages and sometimes the line it points to isn't the actual source of the error; look at above lines as well.
Sorry, you need to Log In to post a reply to this thread.