Thanks!
minkowski
Posts
-
ctime - localtime -> GMT question -
ctime - localtime -> GMT questionHi, Just a quick question on how this conversion from local time to UTC / GMT works in the "gmtime" function. I created a tm object called m_timeinfo as you can see below. I adjusted the month from January to June but it keeps on printing the time as 14:00:00 no matter what month. I would expect that it would print 15:00:00 for January and the same for June. Have I missed a flag or something? Thanks for any input.
tm m_timeinfo; m_timeinfo.tm_mday = 1; m_timeinfo.tm_mon = 2 - 1; // tm struct takes a range from 0 - 11 m_timeinfo.tm_year = 2010 - 1900; // tm struct takes the number of years after 1900 m_timeinfo.tm_hour = 15; m_timeinfo.tm_min = 00; m_timeinfo.tm_sec = 00; tm * ptm = &m_timeinfo; //time_t mktime ( struct tm * timeptr ); time_t useme = mktime ( ptm ); time_t * usemeptr = &useme; //struct tm * gmtime ( const time_t * timer ); tm * result = gmtime ( usemeptr ); std::cout << "year is " << result->tm_year + 1900 << std::endl; std::cout << "month is " << result->tm_mon + 1 << std::endl; std::cout << "day is " << result->tm_mday << std::endl; std::cout << "hour is " << result->tm_hour << std::endl; std::cout << "min is " << result->tm_min << std::endl; std::cout << "sec is " << result->tm_sec << std::endl;
-
quick question on polymorphism [modified]Hi, Think I have got my hair in a mess, say I have a function that accepts a base class ptr, and I want to call a function on a class type that derives from the base class type. Is it possible to just do a dynamic / static cast on it? something like
void func(base* ptr) { //cast down hierachy so i can call my derived class function derived * derivedptr = dynamic_cast(ptr); //call my derived class function derivedptr->derivedfunction(); }
Thanks for any information.modified on Thursday, November 26, 2009 8:30 AM
-
[Message Deleted]Hi, Have a look here http://www.cppreference.com/wiki/string/start[^] HTH
-
question on using kdbgHi, Hope this question is relevant to this forum. Would like to know how to set a break point in kdbg in a .cpp file that is not in the same directory as the exe (such that I cannot see the source code in the debugger where I wish to set the breakpoint). Thanks for any information.
-
Question on g++ compiler optionshey ya Thanks for that. I can see now why it didn't work for the initial -L case. I thought the -L and -l were independent but apparently not ! :)
-
Question on g++ compiler optionsHi ya, Thanks for your reply. The folllowing worked.... g++ -L/home/mpotter/Public/Test/src/mylib.a -I/home/mpotter/Public/Test/header/ main.cpp -o a.out /home/mpotter/Public/Test/src/mylib.a as opposed to g++ -L/home/mpotter/Public/Test/src/ -I/home/mpotter/Public/Test/header/ main.cpp -o a.out mylib.a which did not. also g++ -I/home/mpotter/Public/Test/header/ main.cpp -o a.out /home/mpotter/Public/Test/src/mylib.a works, so I am afraid I don't see the point of using the -L flag to give the location? you can just put the path on the end to your library and it will work fine. I got the g++ -L/home/mpotter/Public/Test/src/ -I/home/mpotter/Public/Test/header/ main.cpp -lmylib -o a.out to work fine. This one with the -l flag makes sense as you use the -L to give the location and -l to give the library name. But the one with just the -L flag (the 1st case) does not make sense to me.... Can you pls explain? Thanks !
-
Question on g++ compiler optionsHey ya, Many thanks for your tips, I tried both but unfortunately I got errors.... For the command line
g++ -L/home/alfred/Public/Test/src -I/home/alfred/Public/Test/header/ main.cpp -o a.out mylib.a
I got the error g++: mylib.a: No such file or directory and for the command line
g++ -L/home/alfred/Public/Test/src/ -I/home/alfred/Public/Test/header/ main.cpp -lmylib.a -o a.out
I got /usr/bin/ld: cannot find -lmylib.a collect2: ld returned 1 exit status even though I have libmylib.a (where the -l substitututes the lib part). Ummm, any ideas? Seems it still can't "see" the mylib.a Many thanks!
-
Question on g++ compiler optionsHi, Am getting to grips with the g++ compiler... I have my main cpp file containing the main function in /home/alfred/Public/Test/ I have my header file in /home/alfred/Public/Test/header/ I have my src file for the header in /home/alfred/Public/Test/src/ I used the command g++ -c -Wall -I/home/alfred/Public/Test/header/ myclass.cpp to generate my myclass.o object file and then the archiver to create the library ar rc mylib.a myclass.o which was fine but now I am having problems compiling and linking the main.cpp file to get my exe. I am trying to use the command g++ -L/home/alfred/Public/Test/src -I/home/alfred/Public/Test/header/ main.cpp -o a.out but I am being returned the error /tmp/ccmZLiDt.o: In function `main': main.cpp:(.text+0x59): undefined reference to `myclass::myclass(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' collect2: ld returned 1 exit status meaning that it cannot see the constructor for the class myclass. I thought the -L flag is to tell it where your library is which has the constructor definition? Ummm, am I getting confused with the -l flag? Thanks for any information. :)
-
switch on multi threading in visual studio using boost librariesHi ya, I've got the enterprise version. Ok I'll try the Boost mailing list. Thanks for your efforts! :)
-
switch on multi threading in visual studio using boost librariesI've got version bjam Boost.Build V2 (Milestone 12) Boost.Jam 03.1.17
-
switch on multi threading in visual studio using boost librariesHmmm, I uninstalled my Boost folder from the previous location and installed it again in "C:\boost" so I can remove the space. I ran your commaned
bjam --toolset=msvc-7.1 --prefix=c:\boost --build-type=complete install
(where c:\boost is the root dir containing all the folders) but still get the errorC:\boost>bjam toolset=msvc-7.1 variant=debug threading=multi link=shared C:/boost/tools/build/v2/tools\msvc.jam:734: in configure-really *** argument error * rule path.make ( native ) * called with: ( ) * missing argument native C:/boost/tools/build/v2/util\path.jam:44:see definition of rule 'make' being called C:/boost/tools/build/v2/tools\msvc.jam:184: in configure C:/boost/tools/build/v2/tools\msvc.jam:137: in msvc.init C:/boost/tools/build/v2/build\toolset.jam:38: in toolset.using C:/boost/tools/build/v2/build\project.jam:862: in using C:\boost\tools/build/v2\user-config.jam:59: in modules.load C:/boost/tools/build/v2\build-system.jam:241: in load-config C:/boost/tools/build/v2\build-system.jam:383: in load-configuration-files C:/boost/tools/build/v2\build-system.jam:520: in load C:\boost\tools\build\v2/kernel\modules.jam:283: in import C:\boost\tools\build\v2\kernel\bootstrap.jam:138: in boost-build C:\boost\boost-build.jam:16: in module scope C:\boost>
So when you installed it you moved all the header folders etc. around?modified on Friday, July 10, 2009 7:49 AM
-
switch on multi threading in visual studio using boost librariesWow, did'nt realise there was so much to do. I ran
bjam --build-dir="c:\program files\boost\boost_1_38\lib" --toolset=msvc --build-type=complete stage
where I have the bjam exe in the \boost_1_38\ directory but it gives an error*** argument error * rule path.make ( native ) * called with: ( ) * missing argument native C:/Program Files/boost/boost_1_38/tools/build/v2/util\path.jam:44:see definition of rule 'make' being called C:/Program Files/boost/boost_1_38/tools/build/v2/tools\msvc.jam:184: in configure C:/Program Files/boost/boost_1_38/tools/build/v2/tools\msvc.jam:137: in msvc.init C:/Program Files/boost/boost_1_38/tools/build/v2/build\toolset.jam:38: in toolset.using C:/Program Files/boost/boost_1_38/tools/build/v2/build\project.jam:862: in using C:\Program Files\boost\boost_1_38\tools/build/v2\user-config.jam:59: in modules.load C:/Program Files/boost/boost_1_38/tools/build/v2\build-system.jam:241: in load-config C:/Program Files/boost/boost_1_38/tools/build/v2\build-system.jam:383: in load-configuration-files C:/Program Files/boost/boost_1_38/tools/build/v2\build-system.jam:520: in load C:\Program Files\boost\boost_1_38\tools\build\v2/kernel\modules.jam:283: in import C:\Program Files\boost\boost_1_38\tools\build\v2\kernel\bootstrap.jam:138: in boost-build C:\Program Files\boost\boost_1_38\boost-build.jam:16: in module scope
Ummm, any ideas? -
switch on multi threading in visual studio using boost librariesHi, I am trying to enable Boost multi threading in Visual Studio 2003.
#include < boost/thread/thread.hpp > // gives errors (see below) #include < boost/lambda/lambda.hpp > // this is ok, no errors reported so it can "see" the boost libraries int main() { return 0; }
I went to PROJECT -> PROPERTIES -> C/C++ -> COMMAND LINE and added/MT
but I get the following compile errorsmain Command line warning D4025 : overriding '/MLd' with '/MT' main Command line warning D4025 : overriding '/MT' with '/MLd' main Command line warning D4025 : overriding '/MLd' with '/MT' main fatal error LNK1104: cannot open file 'libboost_thread-vc71-mt-sgd-1_38.lib'
does anyone know how to switch it on? Had a scout round on the net but to no avail :( Thanks for any information. -
newbie to multi threadingAh excellent. Makes sense! Thanks for your time (and patience!) :)
-
newbie to multi threadingOh I see, so since its the same lock object (
objectMutex
from your example in theget()
andset()
functions) of course it will be locked? -
newbie to multi threadingHey thanks for that, it tidied up some of my uncertainties. I was wondering how C++ knows to lock the other member function if one is being accessed by another thread. In the thread constructor itself you pass in either a function pointer or overloaded
operator()
in your class. So for the case of an object, there must be some reference to thethis
pointer for the object for it to know to lock the other member functions if a lock is in place from another thread. Was wondering if this is correct? Thanks for any information. -
newbie to multi threadingSo from your example, say one thread accesses the
SetMyObject()
, given that there is a lock in the function, it will also lock theGetMyObject()
blocking any other thread from calling? This kind of implies that wherever in the object there is a lock, any function owned by the object will be locked to any other thread trying to access. Is this correct? Thanks again for your help. -
newbie to multi threadingHey thanks for that. So basically, anything that is in the for loop is only executable by 1 thread? If so, what if I have some member functions for a class, say a
get()
and aset()
and I only want one thread at a time to access either of them (preventing a read occuring the same time as a write). How would I lock them? -
difference b/w iterators and indexing for STLHi, This is about the only book you will ever need on the STL. http://www.amazon.co.uk/C-Standard-Library-Tutorial-Reference/dp/0201379260/ref=sr_1_3?ie=UTF8&s=books&qid=1247072015&sr=8-3[^ :) As for your question, it depends on which container you have. If you have a List you cannot use indexing. You must use an iterator to access it. Vector, dequeue offer indexing (random access) and so are faster to access than iterating through every element.