Thank you Andy and Stuart for the reply. I was looking for boost bi-map type functionality. Regards :) :)
ComplexLifeForm
Posts
-
Possible to have a two-way Associative Arrays -
Possible to have a two-way Associative ArraysHi, I am looking for a possibility to have a two way associative array. What I mean is that I would like to have an array say My2WayArray _twoWayArray; and I can do the following _twoWayArray["user1"] = 123; _twoWayArray["user2"] = 456; and _twoWayArray[123] = "user1"; _twoWayArray[456] = "user2"; this way I will be able to lookup a user if the integer (used as user id) is specified and integer id if user name is provided. I don't want to use it anywhere, it is just out of curiosity. While I am posting this question I am trying to figure it out at my end. Thanks and Regards :) :)
-
Confused in choosing a declaration over otherHi, I am confused regarding choosing one declaration from a set of two. I could not decided which one should be preferred over other and why it should be preferred. Please see the declarations below and let me know out of (I) and (II) which declaration is more preferred and why. (I) #if defined (UNICODE) && defined (_UNICODE) typedef std::wstring _tstring; #else typedef std::string _tstring; #endif (II) #if defined (UNICODE) && defined (_UNICODE) #define _tstring std::wstring #else typedef _tstring std::string; #endif Thanks and Regards :) :)
-
How to trace/log 3rd Party library API calls made by an application through WinDbg [modified]Hi, I wish to log/trace all 3rd party library API calls made by the application. I have a 3rd party DLL which exports certain methods and classes and header files containing the class declarations and global methods declaration. Is there a way I can include the header file in windbg for tracing/logging purpose. WinDbg has nice logger, but it logs only standard Windows API calls. Please let me know if this is doable. It can greatly help me to understand the flow of the application. Thanks and Regards :) :)
modified on Friday, June 5, 2009 7:30 AM
-
What is complier actually doing here ?Hi All, I have a query related to virtual methods and access specifiers in C++ class. I have a two classes and their definition is as shown below class Base { public: virtual void PrintMethod() { cout << "Base class method called"; } }; class Derived : public Base { private: virtual void PrintMethod() { cout << "Derived class method called"; } }; in main method int main() { Derived der; Base *ptr = &der; ptr->PrintMethod(); ------------ (1) // der.PrintMethod(); ------------ (2) return 0; } When I execute the program the output I get is "Derived class method called" and this confused me a bit. I could not figure out properly why the derived class method was called when it is private in class Derived? My guess is that the public function in class Base is inherited in Derived class and when the call was made the through the pointer the linker could only find the private definition of the function PrintMethod and hence it called it through the pointer which is actually pointing to the Derived class object. If I try to call the function through the derived class object (as shown in 2), I get compilation error saying the private method is not accessible which is true. So overall I was not satisfied with the reasoning I arrived at for the derived class method being called. Can someone give me more insight into what actually is happening here? Thanks and Regards :) :)
-
How to write assignment operator for a class with constant member variable?Hello Guys, Thanks a lot for your response. As far as the class goes it's not a design issue. I just wanted to find out how to write a proper an assignment operator of for a class with contant member. So it was just out of curosity that I wrote a sample class. Regards :) :)
-
How to write assignment operator for a class with constant member variable?Hi, I have a class with constant member variable. As constant member variables MUST be initialized in the constructor initializer list, how do I write an assignment operator for such a class. E.g. class MyClass { public: MyClass() : m_ConstantMember(0) - (1) {} MyClass(int intvar) : m_ConstantMember(intvar) - (2) {} MyClass(MyClass const& rhs) - (3) : m_ConstantMember(rhs.m_ConstantMember) {} MyClass& operator = (MyClass const& rhs) -- (4) { if(this != &rhs) { m_ConstantMember = rhs.m_ConstantMember; -------- (4a) //memcpy((void*)&m_ConstantMember, (void*)(int*)&rhs.m_ConstantMember, sizeof(m_ConstantMember)) ------------ (4b) } return *this; } private: int const m_ConstantMember; }; The above class has one constant member variable of type int. This variable MUST be initialized in the constructor initializer list. This is achieved in the above class by 1. No argument constructor 2. One argument constructor 3. Copy Constructor For the assignment operator, if I write a statment as in 4a, the compiler complains. However if I write the statement as in 4b, the compiler is happy and I get the desired result. So my query is whether the statement 4b is the correct way of writing an assignment operator for a class with constant member variable? If not can someone please tell me the correct way of writing the assignment operator. Thanks and Regards. :confused::confused:
-
C++ Class Template Full and Partial Specialization queryHi Stuart, Thanks for letting me know that the real issue is with VS2005 SP1 compiler. I will try to get hold of VS 2008 SP1 compiler and try on it. In last two days I went crazy trying to figure out what is wrong with the declaration/definition, now I know the reason. Do you think VS2008 SP1 compiler is the most complete one when it comes to templates specification implementation? And does it supports export keyword for templates? Thanks and Regards :) :)
-
C++ Class Template Full and Partial Specialization queryHi Stuart, Thanks for the help. I tried compiling your code with Visual C++ 2005 Professional SP1 compiler and the compiler gave me the following error :- "error C2768: 'PrintUserData::PrintData' : illegal use of explicit template arguments". "See reference to class template instantiation 'PrintUserData' While the code at (2) compliles properly, the reason could be that the compiler sees t the second declaration/(definition) as a full specialization of member template function for any class. Please correct me if I am wrong template bool PrintData(int const& t1, T2 const& t2)--------------- (1) { std::cout << "Partially specialised Template" << std::endl; return true; } bool PrintData(float const& t1, float const& t2)-------------------- (2) { std::cout << "Function Overload" << std::endl; return true; } On the second thoughts I think there could be an issue with the Visaul C++ 2005 SP1 compiler regarding the template specification implementation Regards :) :)
-
C++ Class Template Full and Partial Specialization queryHi, I have template class with the following declaration template class PrintUserData { public: template bool PrintData (T1 const& t1, T2 const& t2); }; How do I specialize this class and it's overload members for the following 1. Specialize for class MyClass / class UserClass etc 2. Overload PrintData template member for class TextFormater i.e. T1 = T2 = TextFormater 3. Overload PrintData template member for class RtfFormater/class TextFormater i.e. T1 = RtfFormatter/TextFormatter, T2 can be anything 4. Overload PrintData template member for class RtfFormater/class TextFormater i.e. T2 = RtfFormatter/TextFormatter, T1 can be anything I find Full Specialization for specific class is easy e.g. template<> class PrintUserData { // other member }; but I am kind of stuck when I tried to oveload the member method I am trying to get comfortable with C++ Templates so please assist me in obtaining the desired result. If someone feels that the template class declartion needs to be changed to achieve the desired result please let me know. I will change it accordingly Thanks and Regards :) :)
-
Most complete Implementation of C++ specificationHi, I will like to know which C++ compiler implements the most complete C++ and STL Specification/Standards as of today? Also what is the state of latest C++0.x specification (as of today) and conformance of the current compilers? Thanks and Regards :) :)
-
What is the best way of handling a code likeHi, I would like to know if there is a better way of writing a particular pattern of the code as mentioned below. I have been encountering this type quite frequently and do not like the way it is implemented. The code piece is as follows class Address { public: Address():m_address("") {} Address(const CString& addr) : m_address(addr) {} CString GetAddress()------------------ (1) { return m_address; } CString GetAddress() const ------------------ (1a) { return m_address; } const CString& GetAddress() const -----(2) { return m_address; } private: CString m_address; }; Now somewhere in main method Address addr("Living somewhere on Earth"); further down a call is made into a third party library which only takes char* and has a method like void FormatAddress(char* address); -------(3) Now if I make a call to this method, I must do this FormatAddress(const_cast<char*>(addr.GetAddress().GetString()); -------------(4) So my query is whether the whole piece of code is correct, sure it does compile and gives the result as expected but I am looking to improve my programming skills and want to write a better and cleaner code. Out of the methods 1 and 1a which is more correct? Does it makes sense to make the m_address variable as mutable. Thanks and Regards :) :)
-
WPF and mock UIHi All, Can someone please tell me whether WPF can be used to render mock UI say as web pages? What I am looking at is ability to develop quick UI to demo the product/module functionality. If yes can someone please guide me where do I start? Thanks and Regards :) :)
-
Using DotNET API in MFC applicationHi All, I wanted to use NET API in my MFC application, since this was new to me I started out with a simple application listed below #include "stdafx.h" #include "myapp.h" #using #using using namespace System; // The one and only application object CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed\n")); nRetCode = 1; } else { // TODO: code your application's behavior here. Console::WriteLine("This is a MFC app using NET API"); } return nRetCode; } Till few days back I was able to successfully compile and run this simple application using VC++ 2005 with SP1, however now when I am trying to compile the application I am getting the following error 1>.\myapp.cpp(45) : error C3666: 'System::Security::IEvidenceFactory::IEvidenceFactory' : override specifier 'new' not allowed on a constructor 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : error C3611: 'System::Security::IEvidenceFactory::GetLifetimeService': a sealed function cannot have a pure-specifier 1> This diagnostic occurred while importing type 'System::Security::IEvidenceFactory ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : error C4687: 'System::Console': a sealed abstract class cannot implement an interface 'System::Security::IEvidenceFactory' 1> This diagnostic occurred while importing type 'System::Console ' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 1>.\myapp.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation 1> This diagnostic occurred while impor
-
Query on DLL manifest file for a project compiled with VC++ 2005 SP1I managed to make my application totally standalone in the sense that now it can be simply copied and executed on any target machine without worrying whether the proper side-by-side assemblies are installed on target machine or not. For those interested here is link which really helped me http://blog.kalmbach-software.de/2008/05/03/howto-deploy-vc2008-apps-without-installing-vcredist_x86exe Though the article is for VC2008 but it is applicable to VC2005 as well. However there is a small issue with the method mentioned. If your application is dependent on a 3rd party DLL which has embedded manifest file then the method will not work. In such case probably installing the redistributable will be a better idea. Thanks :) :)
-
Query on DLL manifest file for a project compiled with VC++ 2005 SP1Hi, I have checked at Microsoft site and as per the site the version of file for VC++ 2005 redistributable binaries is 8.0.50727.42 and the file version for VC++ 2005 SP1 redistributable binaries is 8.0.50727.762 And there is no redistributable package of VC++ 2005 with or without SP1 for Window 2008. For VC++ 2008 the MFC and CRT version is 9.0.21022.8 The issue is that why is the linker embedding a manifest file for only 1 particular DLL with MFC and CRT libraries as 8.0.50608.0 and from where it is picking that information. I think it should have used this information either for all DLL's/EXE or none of the DLL's/EXE. And as I have mentioned earlier, the Dependency Scanner tool also does not show any dependency of MFC or CRT binaries with file version 8.0.50608.0. So I am confused here. On the machine I am developing I have never installed any Beta or RC version of Visual C++ 2005. Probably installing the redistributable binaries of VC++ 2005 SP1 on the target machine may solve this issue, but that is not the solution I am looking for. Isn't the purpose of using manifest file for EXE/DLL files is to make sure that your application is not affected and always use the same dependencies if someone removes the redistributable binaries from the target machine? Thanks :) :)
-
Query on DLL manifest file for a project compiled with VC++ 2005 SP1Hi, I am using VC++ 2005 with SP1 compiler for my project. The development is being done on Windows XP Pro + SP2 machine but the application is supposed to run on all platforms from Windows 2000 to Windows 2008. The application is a typical MFC application with one executable and many DLL files. Now the query, compiling and running the application on my machine has no issues. However to run the application on the Windows Vista or 2008 I need to have either Visual C++ 2005 SP1 redistributable installed on the target machine or I should be using building the application with SxS assembly isolation in mind and provide the correct manifest for the executables and dll's (either embed it in the binaries or have them as separate file). Also I am relying on VC to generate/embed the manifest file on its own i.e. I am not supplying manifest file explicitly. So while building the application I have chosen to embed the manifest file and set use isolation linker option. I was hoping that it will work properly, but unfortunately it didn't. When I checked I found that the manifest file embedded in one of the Dll's has different information than other DLL's due to which the application could not load the dependency properly. For this particular DLL the embedded manifest file looks like this I have Microsoft.VC80.CRT and Microsoft.VC80.MFC manifest files along with the proper versions of the DLL files in the output directory. I am u
-
Visual Studio 2005 intellisense now showing all the elementsHi, I am using Visual C++ 2005 Pro IDE with SP1 for developing a MFC application. In my application there is a header file which contains application constants inside a namespace like In file AppCommon.h namespace APP_CONSTANTS { const int MAX_BUFFER_SIZE = 100; const CString appStartupMsg = _T("Welcome to application"); .... }; Now when I use this header file and try accessing the variable as APP_CONTANTS:: then the auto complete feature of Visual Studio always shows only the first defined variable. Can someone pleasae tell me how do I get the intellisense to display the other defined variables inside the namespace when trying to use auto complete feature? I have tried deleting all the extra files (ncb, sbr etc...) and tried rebuilding the application for no success. Thanks and Regards :confused::confused:
-
Unable to open file for reading using C++ I/O [modified]Thank you :-D :-D Setting the working directory did solved my problem. But I am not sure why the file gets opened properly if the I try to open it with methods using MFC File I/O. I never had to set the working directory when using MFC File I/O. It could probably be that MFC is setting the working directory automatically. Regards :) :)
modified on Thursday, March 27, 2008 1:42 PM
-
Unable to open file for reading using C++ I/O [modified]Hi I am trying to open a file for reading using C++ I/O. The call to read is simple #include using namspace std; int _tmain() { std::string infile(_T("testreport.txt")); ifstream fin(infile.c_str(), ios::in); if(!fin) { cout << "unable to open file for reading"; } return 0; } when I execute the program I always get the failure. However if I specify the full path to the file like "d:\\testdata\\debug\\testreport.txt", I am able to open the file successfully. I am using VC++ 2005 compiler and debugging with in VC IDE. How do I make VC++ to automatically take the relative path of the file. This problem only occurs when I am debugging through the VC++ IDE. Thanks and Regards
modified on Thursday, March 27, 2008 5:49 AM