iterator dereferencing issue
if I have list<NS*> v; typename list<NS*>::iterator it; for(it = v.begin();it!=v.end();++it){ cout<<**it.ns_member1<<endl; // does not compile NS ns = **it; cout<<ns.ns_member1<<endl; // this compiles. } Why so? ...
if I have list<NS*> v; typename list<NS*>::iterator it; for(it = v.begin();it!=v.end();++it){ cout<<**it.ns_member1<<endl; // does not compile NS ns = **it; cout<<ns.ns_member1<<endl; // this compiles. } Why so? ...
I'm starting a new job next month. I've practically lived inside Visual Studio professionally for 10 years give or take, but for this job I'll be working full time on the linux platform for the first time in my life. During one of the interview meatings I was seated in the middle of the developer room to socialize with the crowd. We had...
I am currently debugging a project in VC6 (slowly porting it over to VS2008). The project links to a DLL that I have produced in VS2008 with a Debug build. (I know - a strange situation to find myself in.) I need to debug the project in VC6 and step into the calls to the DLL. Even though I have the PDB alongside the DLL, VC6 still repor...
In my header file, I'm declaring a map like so: std::map<LPD3DXSPRITE, LPDIRECT3DTEXTURE9> sprites; In my C++ file, I am trying to insert like so: sprites.insert(sprite, texture); The types I am passing to sprites.insert are correct. Why can I not insert this way? What is the proper way to insert? When I do this, the error I get...
I was struggling with the issue described in this question (declaring a template function as a friend of a template class), and I believe the 2nd answer is what I want to do (forward declare the template function, then name a specialization as a friend). I have a question about whether a slightly different solution is actually correct o...
I'm studying C++ right now, coming from a background in Python, and I'm having some trouble understanding how C++ handles multiple source files. In Python, the import statement first checks the current working directory for the module you're trying to import and then it checks the directories in sys.path. In C++, where would I place a cu...
I'm working on a small C++ app that does a bit of string handling. Currently, I want to get extract a string at a particular character index. My naive solution of using string's at() method works fine, but it breaks for non-ascii strings. For example: string test = "ヘ(^_^ヘ)(ノ^_^)ノ" cout << test.at(0) << endl; Produces a pound sign as ...
I have a bunch of classes that each read in their values from an XML file using TinyXML. I've done this so everything is in memory, and my user is using the app and making changes. If the user presses Save, I need to iterate through my objects and call the Save() function which writes out the XML file. Should I rebuild the XML file pr...
I'm trying to implement some STL-style sorting algorithms. The prototype for std::sort looks something like this (from cplusplus.com): template <class RandomAccessIterator> void sort ( RandomAccessIterator first, RandomAccessIterator last ); The function is generally called like this (although the container type can vary): std::vecto...
I get the System image list by calling SHGetImageList: SHGetImageList(SHIL_LAST, IID_IImageList, (void**)&imList); I have a list of 256x256 images, but size of small icons which have not 256 version, have size 256 too. I need to get each icon with it's true size. How can i find out its size? I'm get the size of an icon by using the ...
Hello everyone, I am just learning how to write mutithreaded programs right now and I have a hypothetical question about how many threads are optimal for a program. Let me describe 2 scenarios. The first scenario is that i have a program that is easily multi threaded but each thread is going to be doing a lot of work (execution time...
I have the following code: //Comp454 program 2 #include <iostream> #include <string> #include <fstream> // file I/O support #include <cstdlib> // support for exit() const int SIZE = 60; int main() { using namespace std; string states; int numStates = 0, i = 0, stateVar = 0; string line; char filename[SIZE]; ifstream inFSM, inStri...
I have to implement an HTTP server for a class in C++, but after a connection is accepted, recv() just returns -1. I posted my code belowe, if anyone could help it would be much appreciated. int main( int argc, char* argv[] ) { // Interpret the command line arguments unsigned short port = 8080; char* base_directory = NULL; bas...
In a for loop, I am trying to use printf to print the current i value. This line: printf((char *) i); is giving me runtime errors. Why is this?! Below is a quick fizzbuzz solution that is doing this: void FizzBuzz() { for (int i = 0; i < 20; i++) { printf((char *)i); if ((i % 3 == 0) && (i % 5 == 0)) { pr...
Okay so basically : i have this simple example: main.cpp using namespace VHGO::Resource; std::list<BaseTable*> tableList; BigTable* bt1 = new BigTable(); HRESULT hr = S_OK; hr = bt1->Add(L"TEXTURE", L"..\\Data\\ground.png"); tableList.push_back(bt1); std::wofstream ofs3(L"VHGOSatData.bif"); boost::archive::xml_woarchive outArch3(of...
Hi, The following simple piece of code, compiles with VC2008 but g++ rejects the code: #include <iostream> class myclass { protected: void print() { std::cout << "myclass::print();"; } }; struct access : private myclass { static void access_print(myclass& object) { // g++ and Comeau reject this line but not VC++ ...
Is there a g++ equivalent to Visual Studio's __declspec(novtable) argument? Basically, in a pure virtual base class the __declspec(novtable) argument can be used to suppress the creation of a vtable for the base class as well as vtable initialization/deinitialization code in the contstructor/destructor respectively. E.g., class __decl...
I'm compiling some code that relies on include guards to prevent multiple definitions of objects and functions, but Visual Studio 2008 is giving me link errors that there are multiple definitions. I don't understand why because I've used code very similar to this before and it hasn't caused problems. I must be doing something dumb but I ...
If I create a vector like vector<myClass> v(10); what is the default value of each element? Also, what if it is a vector<myUnion> v(10) ? ...
How does the following example usage of extern specifer behave. We have a global variable int x both in files one.c and two.c We want to use these in three.c so have declared this variable in three.c as extern int x; What would happen when we compile and link these files? My answer is: compilation of all these files should succe...