visual-c++-2005

Function which returns an unknown type

99封情书 提交于 2019-12-04 10:53:06
问题 class Test { public: SOMETHING DoIt(int a) { float FLOAT = 1.2; int INT = 2; char CHAR = 'a'; switch(a) { case 1: return INT; case 2: return FLOAT; case 3: return CHAR; } } }; int main(int argc, char* argv[]) { Test obj; cout<<obj.DoIt(1); return 0; } Now, using the knowledge that a = 1 implies that I need to return an integer, etc., is there anyway Doit() can return a variable of variable data type? Essentially, with what do I replace SOMETHING ? PS: I'm trying to find a an alternative to

Change app icon in Visual Studio 2005?

邮差的信 提交于 2019-12-04 10:53:02
问题 I'd like to use a different icon for the demo version of my game, and I'm building the demo with a different build config than I do for the full verison, using a preprocessor define to lockout some content, use different graphics, etc. Is there a way that I can make Visual Studio use a different icon for the app Icon in the demo config but continue to use the regular icon for the full version's config? 回答1: According to this page you may use preprocessor directives in your *.rc file. You

How to get a full call stack in Visual Studio 2005?

若如初见. 提交于 2019-12-04 09:54:05
How can I get a full call stack for a c++ application developed with Visual Studio 2005? I would like to have a full call stack including the code in the system libraries. Do I have to change some settings in Visual Studio, or do I have to install additional software? Get debug information for all project dependencies. This is specified under the "Configuration Properties -> C/C++ -> General" section of the project properties. On the menu, go to "Tools -> Options" then select "Debugging -> Symbols". Add a new symbol location (the folder icon) that points to Microsoft's free symbol server

False sense of security with `snprintf_s`

给你一囗甜甜゛ 提交于 2019-12-03 10:57:04
问题 MSVC's "secure" sprintf funcions have a template version that 'knows' the size of the target buffer. However, this code happily paints 567890 over the stack after the end of bytes ... char bytes[5]; _snprintf_s( bytes, _TRUNCATE, "%s", "1234567890" ); Any idea what I do wrong, or is this a known bug? (I'm working in VS2005 - didn't test in 2008 or 2010) 回答1: It does appear to be a bug in Visual C++ 2005 (I'm having trouble getting to that link; Google also has it cached). I was able to

Setting file version number in Visual Studio 2005 C++

若如初见. 提交于 2019-12-03 10:51:05
Can anyone point me in the right direction how to configure Visual Studio 2005 with our C++ console project how we can include a 'File Version' in the details section of the file properties. I've tried resource files without any luck. This is with a C++ project just for clarification, and big thank you for the guys you responded with C# suggestions. Thanks in advance. If you are talking about unmanaged c++, you need to add a version resource to the project. right-click on the project, choose add - Resource.... Choose Version and press new. There you can enter all info you need. You have to

Function which returns an unknown type

心不动则不痛 提交于 2019-12-03 06:55:18
class Test { public: SOMETHING DoIt(int a) { float FLOAT = 1.2; int INT = 2; char CHAR = 'a'; switch(a) { case 1: return INT; case 2: return FLOAT; case 3: return CHAR; } } }; int main(int argc, char* argv[]) { Test obj; cout<<obj.DoIt(1); return 0; } Now, using the knowledge that a = 1 implies that I need to return an integer, etc., is there anyway Doit() can return a variable of variable data type? Essentially, with what do I replace SOMETHING ? PS: I'm trying to find a an alternative to returning a structure/union containing these data types. You can use boost::any or boost::variant to do

SSE2 Compiler Error

…衆ロ難τιáo~ 提交于 2019-12-02 06:18:57
问题 I'm trying to break into SSE2 and tried the following example program: #include "stdafx.h" #include <emmintrin.h> int main(int argc, char* argv[]) { __declspec(align(16)) long mul; // multiply variable __declspec(align(16)) int t1[100000]; // temporary variable __declspec(align(16)) int t2[100000]; // temporary variable __m128i mul1, mul2; for (int j = 0; j < 100000; j++) { t1[j] = j; t2[j] = j+1; } // set temporary variables to random values _asm { mov eax, 0 label: movdqa xmm0, xmmword ptr

SSE2 Compiler Error

夙愿已清 提交于 2019-12-02 01:45:49
I'm trying to break into SSE2 and tried the following example program : #include "stdafx.h" #include <emmintrin.h> int main(int argc, char* argv[]) { __declspec(align(16)) long mul; // multiply variable __declspec(align(16)) int t1[100000]; // temporary variable __declspec(align(16)) int t2[100000]; // temporary variable __m128i mul1, mul2; for (int j = 0; j < 100000; j++) { t1[j] = j; t2[j] = j+1; } // set temporary variables to random values _asm { mov eax, 0 label: movdqa xmm0, xmmword ptr [t1+eax] movdqa xmm1, xmmword ptr [t2+eax] pmuludq xmm0, xmm1 movdqa mul1, xmm0 movdqa xmm0, xmmword

Find largest and second largest element in a range

家住魔仙堡 提交于 2019-11-30 14:59:49
How do I find the above without removing the largest element and searching again? Is there a more efficient way to do this? It does not matter if the these elements are duplicates. for (e: all elements) { if (e > largest) { second = largest; largest = e; } else if (e > second) { second = e; } } You could either initialize largest and second to an appropriate lower bound, or to the first two items in the list (check which one is bigger, and don't forget to check if the list has at least two items) using partial_sort ? std::partial_sort(aTest.begin(), aTest.begin() + 2, aTest.end(), Functor); An

Pthreads in Visual C++

十年热恋 提交于 2019-11-30 14:56:51
问题 I'm experimenting with multithreading in Windows and was wondering whether I should use Win32 API use POSIX Threads for Windows Learning Pthreads would be useful if I tried to develop such applications on different platforms - but am I losing anything by not learning Win32 API? Or are both similar enough so that learning one allows me to figure out the other easily? 回答1: Use Boost Threads. When C++0x comes along, we will have std::threads. Boost threads has the closest implementation to std