c++ Programming Glossary: dosomething
Does the 'mutable' keyword have any purpose other than allowing the variable to be modified by a const function? http://stackoverflow.com/questions/105014/does-the-mutable-keyword-have-any-purpose-other-than-allowing-the-variable-to method class Foo private mutable bool done_ public void doSomething const ... done_ true Is this the only use of this keyword or..
Developing C wrapper API for Object-Oriented C++ code http://stackoverflow.com/questions/2045774/developing-c-wrapper-api-for-object-oriented-c-code MyClass public explicit MyClass std string s ~MyClass int doSomething int j Would map to a C interface like this C header struct HMyClass.. const char s void myStruct_destroy HMyClass v int myStruct_doSomething HMyClass v int i The implementation of the interface would look.. HMyClass v delete reinterpret_cast HMyClass v int myStruct_doSomething HMyClass v int i return reinterpret_cast HMyClass v doSomething..
C++ RTTI Viable Examples [closed] http://stackoverflow.com/questions/238452/c-rtti-viable-examples does or does not ... pick your poison inherits from A void doSomething A a typeid name returns the name of the object not portable..
Why should I declare a virtual destructor for an abstract class in C++? http://stackoverflow.com/questions/270917/why-should-i-declare-a-virtual-destructor-for-an-abstract-class-in-c memory leak. For example class Interface virtual void doSomething void 0 class Derived public Interface Derived void ~Derived..
Is it worth setting pointers to NULL in a destructor? http://stackoverflow.com/questions/3060006/is-it-worth-setting-pointers-to-null-in-a-destructor now class Foo public Foo bar new Bar ~Foo delete bar void doSomething bar doSomething private Bar bar As well as deleting the objects.. Foo bar new Bar ~Foo delete bar void doSomething bar doSomething private Bar bar As well as deleting the objects in the destructor..
Why can templates only be implemented in the header file? http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file For example template typename T struct Foo T bar void doSomething T param do stuff using T somewhere in a .cpp Foo int f When.. is equivalent to the following struct FooInt int bar void doSomething int param do stuff using int Consequently the compiler needs.. of the header. Foo.h template typename T struct Foo void doSomething T param #include Foo.tpp Foo.tpp template typename T void Foo..
C++ equivalent of instanceof http://stackoverflow.com/questions/500493/c-equivalent-of-instanceof NewType old if v 0 old was safely casted to NewType v doSomething This requires your compiler to have rtti support enabled. EDIT..
What are access specifiers? Should I inherit with private, protected or public? http://stackoverflow.com/questions/5447498/what-are-access-specifiers-should-i-inherit-with-private-protected-or-public int b private int c class Derived public Base void doSomething a 10 Allowed b 20 Allowed c 30 Not Allowed Compiler Error int.. is OK because for classes it defaults to private void doSomething a 10 Allowed b 20 Allowed c 30 Not Allowed Compiler Error class.. Allowed Compiler Error class Derived2 public Derived void doSomethingMore a 10 Not Allowed Compiler Error a is private member of..
When do function-level static variables get allocated/initialized? http://stackoverflow.com/questions/55510/when-do-function-level-static-variables-get-allocated-initialized But what about static ones defined within a function void doSomething static bool globalish true ... When is the space for globalish.. does it get initialized then too Or is it initialized when doSomething is first called c c variables share improve this question..
When to use std::forward to forward arguments? http://stackoverflow.com/questions/7257144/when-to-use-stdforward-to-forward-arguments call such as this template int val typename... Params void doSomething Params... args doSomethingElse val Params... args... Should.. int val typename... Params void doSomething Params... args doSomethingElse val Params... args... Should I use this instead template.. use this instead template int val typename... Params void doSomething Params ... args doSomethingElse val Params... std forward Params..
What is a smart pointer and when should I use one? http://stackoverflow.com/questions/106508/what-is-a-smart-pointer-and-when-should-i-use-one object to achieve some goal MyObject ptr new MyObject ptr DoSomething Use the object in some way. delete ptr Destroy the object. Done.. delete ptr Destroy the object. Done with it. Wait what if DoSomething raises an exception.... A smart pointer by comparison defines.. destroying it. SomeSmartPtr MyObject ptr new MyObject ptr DoSomething Use the object in some way. Destruction of the object happens..
iterate over tuple http://stackoverflow.com/questions/1198260/iterate-over-tuple Boost.Fusion is a possibility Untested example struct DoSomething template typename T void operator T t const t.do_sth tuple..
In C++, what is a virtual base class? http://stackoverflow.com/questions/21558/in-c-what-is-a-virtual-base-class it means. Let me show an example class Foo public void DoSomething ... class Bar public virtual Foo public void DoSpecific .....
c++ call constructor from constructor http://stackoverflow.com/questions/308276/c-call-constructor-from-constructor used to run through constructors class Test public Test DoSomething public Test int count this DoSomethingWithCount count public.. Test public Test DoSomething public Test int count this DoSomethingWithCount count public Test int count string name this count.. count public Test int count string name this count DoSomethingWithName name Is there a way to do this in c I tried calling..
C++ Dynamic Shared Library on Linux http://stackoverflow.com/questions/496664/c-dynamic-shared-library-on-linux linker will try to perform static linkage virtual void DoSomething private int x #endif myclass.cc #include myclass.h #include.. object delete object MyClass MyClass x 20 void MyClass DoSomething cout x endl class_user.cc #include dlfcn.h #include iostream.. destroy_object MyClass myClass MyClass create myClass DoSomething destroy myClass On Mac OS X compile with g dynamiclib flat_namespace..
C++ overload resolution http://stackoverflow.com/questions/72010/c-overload-resolution example why do I have to explicitly use the statement b A DoSomething rather than just b DoSomething Shouldn't the compiler's overload.. use the statement b A DoSomething rather than just b DoSomething Shouldn't the compiler's overload resolution figure out which.. virtual doesn't help in this case. class A public int DoSomething return 0 class B public A public int DoSomething int x return..
CUDA device to host copy very slow http://stackoverflow.com/questions/12792693/cuda-device-to-host-copy-very-slow to host it takes very long timeļ¼ like ~9s. __global__ void dosomething int d_bPtr .... atomicExch d_bPtr c .... start clock thrust.. end clock cout Time Spent end start endl __global__ void dosomething int d_bPtr .... atomicExch d_bPtr c .... start clock thrust..
What is the practical use of pointers to member functions? http://stackoverflow.com/questions/3957348/what-is-the-practical-use-of-pointers-to-member-functions function such as below suitably defined myfoo and MFN void dosomething myfoo m MFN f m could also be passed by reference to const..
Is it a good practice to use enum as int? http://stackoverflow.com/questions/4963031/is-it-a-good-practice-to-use-enum-as-int the switch statement it would become switch state case One dosomething break case Two dosomething break case Three dosomething break.. become switch state case One dosomething break case Two dosomething break case Three dosomething break So is it a good practice.. dosomething break case Two dosomething break case Three dosomething break So is it a good practice to use enum like this Is there..
How typedef works for function pointers http://stackoverflow.com/questions/9357520/how-typedef-works-for-function-pointers #include stdio.h typedef void print void static void dosomething void printf Hello World n int main void print f1 dosomething.. void printf Hello World n int main void print f1 dosomething print f2 dosomething f2 f1 f1 f2 f1 f2 f1 That compiles cleanly.. Hello World n int main void print f1 dosomething print f2 dosomething f2 f1 f1 f2 f1 f2 f1 That compiles cleanly under gcc O3 g Wall..
|