Search Results

Search found 2886 results on 116 pages for 'std'.

Page 17/116 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • [c++] How to create a std::ofstream to a temp file?

    - by dehmann
    Okay, mkstemp is the preferred way to create a temp file in POSIX. But it opens the file and returns an int, which is a file descriptor. From that I can only create a FILE*, but not an std::ofstream, which I would prefer in C++. (Apparently, on AIX and some other systems, you can create an std::ofstream from a file descriptor, but my compiler complains when I try that.) I know I could get a temp file name with tmpnam and then open my own ofstream with it, but that's apparently unsafe due to race conditions, and results in a compiler warning (g++ v3.4. on Linux): warning: the use of `tmpnam' is dangerous, better use `mkstemp' So, is there any portable way to create an std::ofstream to a temp file?

    Read the article

  • Which libraries use the "We Know Where You Live" optimization for std::make_shared?

    - by KnowItAllWannabe
    Over two years ago, Stephan T. Lavavej described a space-saving optimization he implemented in Microsoft's implementation of std::make_shared, and I know from speaking with him that Microsoft has nothing against other library implementations adopting this optimization. If you know for sure whether other libraries (e.g., for Gnu C++, Clang, Intel C++, plus Boost (for boost::make_shared)) have adopted this implementation, please contribute an answer. I don't have ready access to that many make_shared implementations, nor am I wild about digging into the bowels of the ones I have to see if they've implemented the WKWYL optimization, but I'm hoping that SO readers know the answers for some libraries off-hand. I know from looking at the code that as of Boost 1.52, the WKWYL optimization had not been implemented, but Boost is now up to version 1.55. Note that this optimization is different from std::make_shared's ability to avoid a dedicated heap allocation for the reference count used by std::shared_ptr. For a discussion of the difference between WKWYL and that optimication, consult this question.

    Read the article

  • How would one call std::forward on all arguments in a variadic function?

    - by Noah Roberts
    I was just writing a generic object factory and using the boost preprocessor meta-library to make a variadic template (using 2010 and it doesn't support them). My function uses rval references and std::forward to do perfect forwarding and it got me thinking...when C++0X comes out and I had a standard compiler I would do this with real variadic templates. How though, would I call std::forward on the arguments? template < typename ... Params void f(Params ... params) // how do I say these are rvalue reference? { y(std::forward(...params)); //? - I doubt this would work. } Only way I can think of would require manual unpacking of ...params and I'm not quite there yet either. Is there a quicker syntax that would work?

    Read the article

  • Why is the volatile qualifier used through out std::atomic?

    - by Caspin
    From what I've read from Herb Sutter and others you would think that volatile and concurrent programming were completely orthogonal concepts, at least as far as C/C++ are concerned. However, in GCC c++0x extension all of std::atomic's member functions have the volatile qualifier. The same is true in Anthony Williams's implementation of std::atomic. So what's deal, do my atomic<> variables need be volatile or not?

    Read the article

  • Way to get unsigned char into a std::string without reinterpret_cast?

    - by WilliamKF
    I have an unsigned char array that I need in a std::string, but my current way uses reinterpret_cast which I would like to avoid. Is there a cleaner way to do this? unsigned char my_txt[] = { 0x52, 0x5f, 0x73, 0x68, 0x7e, 0x29, 0x33, 0x74, 0x74, 0x73, 0x72, 0x55 } unsigned int my_txt_len = 12; std::string my_std_string(reinterpret_cast<const char *>(my_txt), my_txt_len);

    Read the article

  • OpenGL textures trigger error 1281 if SFML is not called

    - by user3714670
    I am using SOIL to apply textures to VBOs, without textures i could change the background and display black (default color) vbos easily, but now with textures, openGL is giving an error 1281, the background is black and some textures are not applied. but the first texture IS applied (nothing else is working though). The strange thing is : if i create a dummy texture with SFML in the same program, all other textures do work. So i guess there is something i forgot in the texture creation/application, if someone could enlighten me. Here is the code i use to load textures, once loaded it is kept in memory, it mostly comes from the example of SOIL : texture = SOIL_load_OGL_single_cubemap( filename, SOIL_DDS_CUBEMAP_FACE_ORDER, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_DDS_LOAD_DIRECT ); if( texture > 0 ) { glEnable( GL_TEXTURE_CUBE_MAP ); glEnable( GL_TEXTURE_GEN_S ); glEnable( GL_TEXTURE_GEN_T ); glEnable( GL_TEXTURE_GEN_R ); glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP ); glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP ); glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP ); glBindTexture( GL_TEXTURE_CUBE_MAP, texture ); std::cout << "the loaded single cube map ID was " << texture << std::endl; } else { std::cout << "Attempting to load as a HDR texture" << std::endl; texture = SOIL_load_OGL_HDR_texture( filename, SOIL_HDR_RGBdivA2, 0, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS ); if( texture < 1 ) { std::cout << "Attempting to load as a simple 2D texture" << std::endl; texture = SOIL_load_OGL_texture( filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_DDS_LOAD_DIRECT ); } if( texture > 0 ) { // enable texturing glEnable( GL_TEXTURE_2D ); // bind an OpenGL texture ID glBindTexture( GL_TEXTURE_2D, texture ); std::cout << "the loaded texture ID was " << texture << std::endl; } else { glDisable( GL_TEXTURE_2D ); std::cout << "Texture loading failed: '" << SOIL_last_result() << "'" << std::endl; } } and how i apply it when drawing : GLuint TextureID = glGetUniformLocation(shaderProgram, "myTextureSampler"); if(!TextureID) cout << "TextureID not found ..." << endl; // glEnableVertexAttribArray(TextureID); glActiveTexture(GL_TEXTURE0); if(SFML) sf::Texture::bind(sfml_texture); else { glBindTexture (GL_TEXTURE_2D, texture); // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1024, 768, 0, GL_RGB, GL_UNSIGNED_BYTE, &texture); } glUniform1i(TextureID, 0); I am not sure that SOIL is adapted to my program as i want something as simple as possible (i used sfml's texture object which was the best but i can't anymore), but if i can get it to work it would be great.

    Read the article

  • Creating a voxel world with 3D arrays using threads

    - by Sean M.
    I am making a voxel game (a bit like Minecraft) in C++(11), and I've come across an issue with creating a world efficiently. In my program, I have a World class, which holds a 3D array of Region class pointers. When I initialize the world, I give it a width, height, and depth so it knows how large of a world to create. Each Region is split up into a 32x32x32 area of blocks, so as you may guess, it takes a while to initialize the world once the world gets to be above 8x4x8 Regions. In order to alleviate this issue, I thought that using threads to generate different levels of the world concurrently would make it go faster. Having not used threads much before this, and being still relatively new to C++, I'm not entirely sure how to go about implementing one thread per level (level being a xz plane with a height of 1), when there is a variable number of levels. I tried this: for(int i = 0; i < height; i++) { std::thread th(std::bind(&World::load, this, width, height, depth)); th.join(); } Where load() just loads all Regions at height "height". But that executes the threads one at a time (which makes sense, looking back), and that of course takes as long as generating all Regions in one loop. I then tried: std::thread t1(std::bind(&World::load, this, w, h1, h2 - 1, d)); std::thread t2(std::bind(&World::load, this, w, h2, h3 - 1, d)); std::thread t3(std::bind(&World::load, this, w, h3, h4 - 1, d)); std::thread t4(std::bind(&World::load, this, w, h4, h - 1, d)); t1.join(); t2.join(); t3.join(); t4.join(); This works in that the world loads about 3-3.5 times faster, but this forces the height to be a multiple of 4, and it also gives the same exact VAO object to every single Region, which need individual VAOs in order to render properly. The VAO of each Region is set in the constructor, so I'm assuming that somehow the VAO number is not thread safe or something (again, unfamiliar with threads). So basically, my question is two one-part: How to I implement a variable number of threads that all execute at the same time, and force the main thread to wait for them using join() without stopping the other threads? How do I make the VAO objects thread safe, so when a bunch of Regions are being created at the same time across multiple threads, they don't all get the exact same VAO? Turns out it has to do with GL contexts not working across multiple threads. I moved the VAO/VBO creation back to the main thread. Fixed! Here is the code for block.h/.cpp, region.h/.cpp, and CVBObject.h/.cpp which controls VBOs and VAOs, in case you need it. If you need to see anything else just ask. EDIT: Also, I'd prefer not to have answers that are like "you should have used boost". I'm trying to do this without boost to get used to threads before moving onto other libraries.

    Read the article

  • iPhone Store Kit returning invalid product ID errors

    - by EToreo
    Hello, I am trying to test In App Purchases on my iPhone and running into a problem where the product IDs I request information for end up being returned to me as invalid product IDs in the "didRecieveResponse" method. I have: Created an in store product associated with this app. It's bundle ID matches everything else. It has been cleared for sale and approved by the developer. Made sure my new provisioning profile has in store app purchases enabled and it has the full app name: "com.domain.appname" Made sure this is the provisioning profile being used to sign the app to my iPhone. Made sure that "com.domain.appname" is the app ID used to build the provisioning profile. Made sure that "com.domain.appname" is used in my plist file as the bundle identifier. Everything seems to be in place, however I still get my products returned to me as invalid IDs. This is the code I am using: - (void)requestProductData { SKProductRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"com.domain.appname.productid"]]; request.delegate = self; [request start]; } - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { NSArray *myProducts = response.products; NSArray *myInvalidProducts = response.invalidProductIdentifiers; for(int i = 1; i < myInvalidProducts.count; ++i) { std::cout <<"invalid product id = " << [[myInvalidProducts objectAtIndex:i] UTF8String] << std::endl; } for(int i = 0; i < myProducts.count; ++i) { SKProduct * myProduct = [myProducts objectAtIndex:i]; std::cout << "Product Info:" << std::endl; std::cout << "\tlocalizedTitle = " << [[myProduct localizedTitle] UTF8String] << std::endl; std::cout << "\tlocalizedDescription = " << [[myProduct localizedDescription] UTF8String] << std::endl; std::cout << "\tproductIdentifier = " << [[myProduct productIdentifier] UTF8String] << std::endl; std::cout << "\tprice = " << [[myProduct price] doubleValue] << std::endl; std::cout << "\tpriceLocale = " << [myProduct priceLocale] << std::endl; } [request autorelease]; } All my product IDs show up in the invalid printouts and none of them show up in the "Product Info:" printouts. Any suggestions would be greatly appreciated... P.S. Yes, this is built as Objective-c/c++.

    Read the article

  • simple C++ hash_set example

    - by celil
    I am new to C++ and STL. I am stuck with the following simple example of a hash set storing custom data structures: #include <iostream> #include <ext/hash_set> using namespace std; using namespace __gnu_cxx; struct trip { int trip_id; int delta_n; int delta_secs; trip(int trip_id, int delta_n, int delta_secs){ this->trip_id = trip_id; this->delta_n = delta_n; this->delta_secs = delta_secs; } }; struct hash_trip { size_t operator()(const trip t) { hash<int> H; return H(t.trip_id); } }; struct eq_trip { bool operator()(const trip t1, const trip t2) { return (t1.trip_id==t2.trip_id) && (t1.delta_n==t2.delta_n) && (t1.delta_secs==t2.delta_secs); } }; int main() { hash_set<trip, hash_trip, eq_trip> trips; trip t = trip(3,2,-1); trip t1 = trip(3,2,0); trips.insert(t); } when I try to compile it, I get the following error message: /usr/include/c++/4.2.1/ext/hashtable.h: In member function ‘size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num_key(const _Key&, size_t) const [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity<trip>, _EqualKey = eq_trip, _Alloc = std::allocator<trip>]’: /usr/include/c++/4.2.1/ext/hashtable.h:599: instantiated from ‘size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num(const _Val&, size_t) const [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity<trip>, _EqualKey = eq_trip, _Alloc = std::allocator<trip>]’ /usr/include/c++/4.2.1/ext/hashtable.h:1006: instantiated from ‘void __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::resize(size_t) [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity<trip>, _EqualKey = eq_trip, _Alloc = std::allocator<trip>]’ /usr/include/c++/4.2.1/ext/hashtable.h:437: instantiated from ‘std::pair<__gnu_cxx::_Hashtable_iterator<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>, bool> __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::insert_unique(const _Val&) [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity<trip>, _EqualKey = eq_trip, _Alloc = std::allocator<trip>]’ /usr/include/c++/4.2.1/ext/hash_set:197: instantiated from ‘std::pair<typename __gnu_cxx::hashtable<_Value, _Value, _HashFcn, std::_Identity<_Value>, _EqualKey, _Alloc>::const_iterator, bool> __gnu_cxx::hash_set<_Value, _HashFcn, _EqualKey, _Alloc>::insert(const typename __gnu_cxx::hashtable<_Value, _Value, _HashFcn, std::_Identity<_Value>, _EqualKey, _Alloc>::value_type&) [with _Value = trip, _HashFcn = hash_trip, _EqualKey = eq_trip, _Alloc = std::allocator<trip>]’ try.cpp:45: instantiated from here /usr/include/c++/4.2.1/ext/hashtable.h:595: error: passing ‘const hash_trip’ as ‘this’ argument of ‘size_t hash_trip::operator()(trip)’ discards qualifiers What am I doing wrong?

    Read the article

  • How to write a streaming 'operator<<' that can take arbitary containers (of type 'X')?

    - by Drew Dormann
    I have a C++ class "X" which would have special meaning if a container of them were to be sent to a std::ostream. I originally implemented it specifically for std::vector<X>: std::ostream& operator << ( std::ostream &os, const std::vector<X> &c ) { // The specialized logic here expects c to be a "container" in simple // terms - only that c.begin() and c.end() return input iterators to X } If I wanted to support std::ostream << std::deque<X> or std::ostream << std::set<X> or any similar container type, the only solution I know of is to copy-paste the entire function and change only the function signature! Is there a way to generically code operator << ( std::ostream &, const Container & )? ("Container" here would be any type that satisfies the commented description above.)

    Read the article

  • Issue Parsing File with YAML-CPP

    - by Andrew
    In the following code, I'm having some sort of issue getting my .yaml file parsed using parser.GetNextDocument(doc);. After much gross debugging, I've found that the (main) issue here is that my for loop is not running, due to doc.size() == 0; What am I doing wrong? void BookView::load() { aBook.clear(); QString fileName = QFileDialog::getOpenFileName(this, tr("Load Address Book"), "", tr("Address Book (*.yaml);;All Files (*)")); if(fileName.isEmpty()) { return; } else { try { std::ifstream fin(fileName.toStdString().c_str()); YAML::Parser parser(fin); YAML::Node doc; std::map< std::string, std::string > entry; parser.GetNextDocument(doc); std::cout << doc.size(); for( YAML::Iterator it = doc.begin(); it != doc.end(); it++ ) { *it >> entry; aBook.push_back(entry); } } catch(YAML::ParserException &e) { std::cout << "YAML Exception caught: " << e.what() << std::endl; } } updateLayout( Navigating ); } The .yaml file being read was generated using yaml-cpp, so I assume it is correctly formed YAML, but just in case, here's the file anyways. ^@^@^@\230--- - address: ****************** comment: None. email: andrew(dot)levenson(at)gmail(dot)com name: Andrew Levenson phone: **********^@ Edit: By request, the emitting code: void BookView::save() { QString fileName = QFileDialog::getSaveFileName(this, tr("Save Address Book"), "", tr("Address Book (*.yaml);;All Files (*)")); if (fileName.isEmpty()) { return; } else { QFile file(fileName); if(!file.open(QIODevice::WriteOnly)) { QMessageBox::information(this, tr("Unable to open file"), file.errorString()); return; } std::vector< std::map< std::string, std::string > >::iterator itr; std::map< std::string, std::string >::iterator mItr; YAML::Emitter yaml; yaml << YAML::BeginSeq; for( itr = aBook.begin(); itr < aBook.end(); itr++ ) { yaml << YAML::BeginMap; for( mItr = (*itr).begin(); mItr != (*itr).end(); mItr++ ) { yaml << YAML::Key << (*mItr).first << YAML::Value << (*mItr).second; } yaml << YAML::EndMap; } yaml << YAML::EndSeq; QDataStream out(&file); out.setVersion(QDataStream::Qt_4_5); out << yaml.c_str(); } }

    Read the article

  • Use of for_each on map elements

    - by Antonio
    I have a map where I'd like to perform a call on every data type object member function. I yet know how to do this on any sequence but, is it possible to do it on an associative container? The closest answer I could find was this: Boost.Bind to access std::map elements in std::for_each. But I cannot use boost in my project so, is there an STL alternative that I'm missing to boost::bind? If not possible, I thought on creating a temporary sequence for pointers to the data objects and then, call for_each on it, something like this: class MyClass { public: void Method() const; } std::map<int, MyClass> Map; //... std::vector<MyClass*> Vector; std::transform(Map.begin(), Map.end(), std::back_inserter(Vector), std::mem_fun_ref(&std::map<int, MyClass>::value_type::second)); std::for_each(Vector.begin(), Vector.end(), std::mem_fun(&MyClass::Method)); It looks too obfuscated and I don't really like it. Any suggestions?

    Read the article

  • Problem in running boost eample blocking_udp_echo_client on MacOSX

    - by n179911
    I am trying to run blocking_udp_echo_client on MacOS X http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/example/echo/blocking_udp_echo_client.cpp I run it with argument 'localhost 9000' But the program crashes and this is the line in the source which crashes: `udp::socket s(io_service, udp::endpoint(udp::v4(), 0));' this is the stack trace: #0 0x918c3e42 in __kill #1 0x918c3e34 in kill$UNIX2003 #2 0x9193623a in raise #3 0x91942679 in abort #4 0x940d96f9 in __gnu_debug::_Error_formatter::_M_error #5 0x0000e76e in __gnu_debug::_Safe_iterator::op_base* , __gnu_debug_def::list::op_base*, std::allocator::op_base* ::_Safe_iterator at safe_iterator.h:124 #6 0x00014729 in boost::asio::detail::hash_map::op_base*::bucket_type::bucket_type at hash_map.hpp:277 #7 0x00019e97 in std::_Construct::op_base*::bucket_type, boost::asio::detail::hash_map::op_base*::bucket_type at stl_construct.h:81 #8 0x0001a457 in std::__uninitialized_fill_n_aux::op_base*::bucket_type*, __gnu_norm::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type , unsigned long, boost::asio::detail::hash_map::op_base*::bucket_type at stl_uninitialized.h:194 #9 0x0001a4e1 in std::uninitialized_fill_n::op_base*::bucket_type*, __gnu_norm::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type , unsigned long, boost::asio::detail::hash_map::op_base*::bucket_type at stl_uninitialized.h:218 #10 0x0001a509 in std::__uninitialized_fill_n_a::op_base*::bucket_type*, __gnu_norm::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type , unsigned long, boost::asio::detail::hash_map::op_base*::bucket_type, boost::asio::detail::hash_map::op_base*::bucket_type at stl_uninitialized.h:310 #11 0x0001aa34 in __gnu_norm::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type ::_M_fill_insert at vector.tcc:365 #12 0x0001acda in __gnu_norm::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type ::insert at stl_vector.h:658 #13 0x0001ad81 in __gnu_norm::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type ::resize at stl_vector.h:427 #14 0x0001ae3a in __gnu_debug_def::vector::op_base*::bucket_type, std::allocator::op_base*::bucket_type ::resize at vector:169 #15 0x0001b7be in boost::asio::detail::hash_map::op_base*::rehash at hash_map.hpp:221 #16 0x0001bbeb in boost::asio::detail::hash_map::op_base*::hash_map at hash_map.hpp:67 #17 0x0001bc74 in boost::asio::detail::reactor_op_queue::reactor_op_queue at reactor_op_queue.hpp:42 #18 0x0001bd24 in boost::asio::detail::kqueue_reactor::kqueue_reactor at kqueue_reactor.hpp:86 #19 0x0001c000 in boost::asio::detail::service_registry::use_service at service_registry.hpp:109 #20 0x0001c14d in boost::asio::use_service at io_service.ipp:195 #21 0x0001c26d in boost::asio::detail::reactive_socket_service ::reactive_socket_service at reactive_socket_service.hpp:111 #22 0x0001c344 in boost::asio::detail::service_registry::use_service at service_registry.hpp:109 #23 0x0001c491 in boost::asio::use_service at io_service.ipp:195 #24 0x0001c4d5 in boost::asio::datagram_socket_service::datagram_socket_service at datagram_socket_service.hpp:95 #25 0x0001c59e in boost::asio::detail::service_registry::use_service at service_registry.hpp:109 #26 0x0001c6eb in boost::asio::use_service at io_service.ipp:195 #27 0x0001c711 in boost::asio::basic_io_object ::basic_io_object at basic_io_object.hpp:72 #28 0x0001c783 in boost::asio::basic_socket ::basic_socket at basic_socket.hpp:108 #29 0x0001c865 in boost::asio::basic_datagram_socket ::basic_datagram_socket at basic_datagram_socket.hpp:107 #30 0x000027bc in main at main.cpp:32 This is the gdb output: (gdb) continue /Developer/SDKs/MacOSX10.5.sdk/usr/include/c++/4.0.0/debug/safe_iterator.h:127: error: attempt to copy-construct an iterator from a singular iterator. Objects involved in the operation: iterator "this" @ 0x0x100420 { type = N11__gnu_debug14_Safe_iteratorIN10__gnu_norm14_List_iteratorISt4pairIiPN5boost4asio6detail16reactor_op_queueIiE7op_baseEEEEN15__gnu_debug_def4listISB_SaISB_EEEEE (mutable iterator); state = singular; } iterator "other" @ 0x0xbfffe8a4 { type = N11__gnu_debug14_Safe_iteratorIN10__gnu_norm14_List_iteratorISt4pairIiPN5boost4asio6detail16reactor_op_queueIiE7op_baseEEEEN15__gnu_debug_def4listISB_SaISB_EEEEE (mutable iterator); state = singular; } Program received signal: “SIGABRT”. (gdb) continue Program received signal: “?”. Does someone has any idea why this example does not work on mac osx? Thank you.

    Read the article

  • How to simulate inner exception in C++

    - by Siva Chandran
    Basically I want to simulate .NET Exception.InnerException in C++. I want to catch exception from bottom layer and wrap it with another exception and throw again to upper layer. The problem here is I don't know how to wrap the catched exception inside another exception. struct base_exception : public std::exception { std::exception& InnerException; base_exception() : InnerException(???) { } // <---- what to initialize with base_exception(std::exception& innerException) : InnerException(innerException) { } }; struct func1_exception : public base_exception { const char* what() const throw() { return "func1 exception"; } }; struct func2_exception : public base_exception { const char* what() const throw() { return "func2 exception"; } }; void func2() { throw func2_exception(); } void func1() { try { func2(); } catch(std::exception& e) { throw func2_exception(e); // <--- is this correct? will the temporary object will be alive? } } int main(void) { try { func1(); } catch(base_exception& e) { std::cout << "Got exception" << std::endl; std::cout << e.what(); std::cout << "InnerException" << std::endl; std::cout << e.InnerException.what(); // <---- how to make sure it has inner exception ? } } In the above code listing I am not sure how to initialize the "InnerException" member when there is no inner exception. Also I am not sure whether the temporary object that is thrown from func1 will survive even after func2 throw?

    Read the article

  • Memory leak dyld dlopen

    - by imthi
    I am getting leak and I cannot detect from where this is happening. The stack trace does not give full info after dyld open. For few leaks I am not getting any stack trace info. All I get is only object memory address. Is anyone else facing the same issue. I am using XCode 3.2 on show leopard. 18 0x103038 17 0x1033c7 16 0x1034a1 15 0x90145f48 14 dyld dlopen 13 dyld dyld::link(ImageLoader*, bool, ImageLoader::RPathChain const&) 12 dyld ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, ImageLoader::RPathChain const&) 11 dyld ImageLoader::recursiveLoadLibraries(ImageLoader::LinkContext const&, bool, ImageLoader::RPathChain const&) 10 dyld dyld::libraryLocator(char const*, bool, char const*, ImageLoader::RPathChain const*) 9 dyld dyld::load(char const*, dyld::LoadContext const&) 8 dyld dyld::loadPhase0(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*) 7 dyld dyld::loadPhase1(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*) 6 dyld dyld::loadPhase3(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*) 5 dyld dyld::loadPhase4(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*) 4 dyld dyld::loadPhase5(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*) 3 dyld dyld::mkstringf(char const*, ...) 2 dyld strdup 1 dyld mallocenter

    Read the article

  • Link error (LNK2019) when including other projects in Visual Studio 2005

    - by jules
    I am trying to work with several projects on visual studio 2005. I have one project that depends on two others. I have included those two project in the first project solution, and set the dependencies correctly. I get this error when linking the project: 1>server_controller.obj : error LNK2019: unresolved external symbol "public: __thiscall server_communication::TcpServer::TcpServer(class boost::asio::io_service &,struct server_communication::ServerParameters &)" (??0TcpServer@server_communication@@QAE@AAVio_service@asio@boost@@AAUServerParameters@1@@Z) referenced in function "public: __thiscall server_controller::ServerController::ServerController(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0ServerController@server_controller@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) I seems that the symbols can not be found in the other projects, even though there are defined in those projects.

    Read the article

  • LNK2001 error when compiling windows forms application with VC++ 2008

    - by Blin
    I've been trying to write a small application which will work with mysql in C++. I am using MySQL server 5.1.41 and MySQL C++ connector 1.0.5. Everything compiles fine when i write console applications, but when i try to compile windows forms application exactly the same way (same libraries, same paths, same project properties) i get this errors: Error 1 error LNK2001: unresolved external symbol "public: virtual int __clrcall sql::mysql::MySQL_Savepoint::getSavepointId(void)" (?getSavepointId@MySQL_Savepoint@mysql@sql@@$$FUAMHXZ) test1.obj test1 Error 2 error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __clrcall sql::mysql::MySQL_Savepoint::getSavepointName(void)" (?getSavepointName@MySQL_Savepoint@mysql@sql@@$$FUAM?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) test1.obj test1 following instructions from here, i've got this: Undecoration of :- "?getSavepointId@MySQL_Savepoint@mysql@sql@@UEAAHXZ" is :- "public: virtual int __cdecl sql::mysql::MySQL_Savepoint::getSavepointId(void) __ptr64" Undecoration of :- "?getSavepointName@MySQL_Savepoint@mysql@sql@@UEAA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ" is :- "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl sql::mysql::MySQL_Savepoint::getSavepointName(void) __ptr64" but what should i do now?

    Read the article

  • Supporting Piping (A Useful Hello World)

    - by blastthisinferno
    I am trying to write a collection of simple C++ programs that follow the basic Unix philosophy by: Make each program do one thing well. Expect the output of every program to become the input to another, as yet unknown, program. I'm having an issue trying to get the output of one to be the input of the other, and getting the output of one be the input of a separate instance of itself. Very briefly, I have a program add which takes arguments and spits out the summation. I want to be able to pipe the output to another add instance. ./add 1 2 | ./add 3 4 That should yield 6 but currently yields 10. I've encountered two problems: The cin waits for user input from the console. I don't want this, and haven't been able to find a simple example showing a the use of standard input stream without querying the user in the console. If someone knows of an example please let me know. I can't figure out how to use standard input while supporting piping. Currently, it appears it does not work. If I issue the command ./add 1 2 | ./add 3 4 it results in 7. The relevant code is below: add.cpp snippet // ... COMMAND LINE PROCESSING ... std::vector<double> numbers = multi.getValue(); // using TCLAP for command line parsing if (numbers.size() > 0) { double sum = numbers[0]; double arg; for (int i=1; i < numbers.size(); i++) { arg = numbers[i]; sum += arg; } std::cout << sum << std::endl; } else { double input; // right now this is test code while I try and get standard input streaming working as expected while (std::cin) { std::cin >> input; std::cout << input << std::endl; } } // ... MORE IRRELEVANT CODE ... So, I guess my question(s) is does anyone see what is incorrect with this code in order to support piping standard input? Are there some well known (or hidden) resources that explain clearly how to implement an example application supporting the basic Unix philosophy? @Chris Lutz I've changed the code to what's below. The problem where cin still waits for user input on the console, and doesn't just take from the standard input passed from the pipe. Am I missing something trivial for handling this? I haven't tried Greg Hewgill's answer yet, but don't see how that would help since the issue is still with cin. // ... COMMAND LINE PROCESSING ... std::vector<double> numbers = multi.getValue(); // using TCLAP for command line parsing double sum = numbers[0]; double arg; for (int i=1; i < numbers.size(); i++) { arg = numbers[i]; sum += arg; } // right now this is test code while I try and get standard input streaming working as expected while (std::cin) { std::cin >> arg; std::cout << arg << std::endl; } std::cout << sum << std::endl; // ... MORE IRRELEVANT CODE ...

    Read the article

  • template class: ctor against function -> new C++ standard

    - by Oops
    Hi in this question: http://stackoverflow.com/questions/2779155/template-point2-double-point3-double Dennis and Michael noticed the unreasonable foolishly implemented constructor. They were right, I didn't consider this at that moment. But I found out that a constructor does not help very much for a template class like this one, instead a function is here much more convenient and safe namespace point { template < unsigned int dims, typename T > struct Point { T X[ dims ]; std::string str() { std::stringstream s; s << "{"; for ( int i = 0; i < dims; ++i ) { s << " X" << i << ": " << X[ i ] << (( i < dims -1 )? " |": " "); } s << "}"; return s.str(); } Point<dims, int> toint() { Point<dims, int> ret; std::copy( X, X+dims, ret.X ); return ret; } }; template < typename T > Point< 2, T > Create( T X0, T X1 ) { Point< 2, T > ret; ret.X[ 0 ] = X0; ret.X[ 1 ] = X1; return ret; } template < typename T > Point< 3, T > Create( T X0, T X1, T X2 ) { Point< 3, T > ret; ret.X[ 0 ] = X0; ret.X[ 1 ] = X1; ret.X[ 2 ] = X2; return ret; } template < typename T > Point< 4, T > Create( T X0, T X1, T X2, T X3 ) { Point< 4, T > ret; ret.X[ 0 ] = X0; ret.X[ 1 ] = X1; ret.X[ 2 ] = X2; ret.X[ 3 ] = X3; return ret; } }; int main( void ) { using namespace point; Point< 2, double > p2d = point::Create( 12.3, 34.5 ); Point< 3, double > p3d = point::Create( 12.3, 34.5, 56.7 ); Point< 4, double > p4d = point::Create( 12.3, 34.5, 56.7, 78.9 ); //Point< 3, double > p1d = point::Create( 12.3, 34.5 ); //no suitable user defined conversion exists //Point< 3, int > p1i = p4d.toint(); //no suitable user defined conversion exists Point< 2, int > p2i = p2d.toint(); Point< 3, int > p3i = p3d.toint(); Point< 4, int > p4i = p4d.toint(); std::cout << p2d.str() << std::endl; std::cout << p3d.str() << std::endl; std::cout << p4d.str() << std::endl; std::cout << p2i.str() << std::endl; std::cout << p3i.str() << std::endl; std::cout << p4i.str() << std::endl; char c; std::cin >> c; } has the new C++ standard any new improvements, language features or simplifications regarding this aspect of ctor of a template class? what do you think about the implementation of the combination of namespace, stuct and Create function? many thanks in advance Oops

    Read the article

  • C++ destructor problem with boost::scoped_ptr

    - by bb-generation
    I have a question about the following code: #include <iostream> #include <boost/scoped_ptr.hpp> class Interface { }; class A : public Interface { public: A() { std::cout << "A()" << std::endl; } virtual ~A() { std::cout << "~A()" << std::endl; } }; Interface* get_a() { A* a = new A; return a; } int main() { { std::cout << "1" << std::endl; boost::scoped_ptr<Interface> x(get_a()); std::cout << "2" << std::endl; } std::cout << "3" << std::endl; } It creates the following output: 1 A() 2 3 As you can see, it doesn't call the destructor of A. The only way I see to get the destructor of A being called, is to add a destructor for the Interface class like this: virtual ~Interface() { } But I really want to avoid any Implementation in my Interface class and virtual ~Interface() = 0; doesn't work (produces some linker errors complaining about a non existing implementation of ~Interface(). So my question is: What do I have to change in order to make the destructor being called, but (if possible) leave the Interface as an Interface (only abstract methods).

    Read the article

  • Using deprecated binders and C++0x lambdas

    - by Sumant
    C++0x has deprecated the use of old binders such as bind1st and bind2nd in favor of generic std::bind. C++0x lambdas bind nicely with std::bind but they don't bind with classic bind1st and bind2nd because by default lambdas don't have nested typedefs such as argument_type, first_argument_type, second_argument_type, and result_type. So I thought std::function can serve as a standard way to bind lambdas to the old binders because it exposes the necessary typedefs. However, using std::function is hard to use in this context because it forces you to spell out the function-type while instantiating it. auto bound = std::bind1st(std::function<int (int, int)>([](int i, int j){ return i < j; }), 10); // hard to use auto bound = std::bind1st(std::make_function([](int i, int j){ return i < j; }), 10); // nice to have but does not compile. I could not find a convenient object generator for std::function. Something like std::make_fuction would be nice to have. Does such a thing exist? If not, is there any other better way of binding lamdas to the classic binders?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >