First  |  Prev |  Next  |  Last
Pages: 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
Function template specialization
template<class T, class U> void f(T t, U u){cout << "1";} template<> void f(char t, char u){cout << "2";} // A template<class T> void f(T t, T u){cout << "3";} template<> void f(char t, char u){cout << "4";} // B int main(){ f('A', 'B'); } I expected that this code is ill-formed due to t... 10 Nov 2009 09:31
union members accessed with another member (whose data type requires less space)
On Nov 9, 12:01 pm, Francis Glassborow <francis.glassbo...(a)btinternet.com> wrote: Trying to read a union through a different field than the one by which it was written is strictly undefined behaviour (there are some special cases which are exceptions). I believe this is the intended reading of the C and C+... 10 Nov 2009 08:03
union members accessed with another member (whose data type requires less space)
krishna wrote: int main() { union my_union{ int i; float f; }; my_union u; u.f = 2.0; std::cout << u.i; } why is int casted value of u.f not given? (the start address is the same for all the members). -Krishna. FOFL That is not how unions work. They are a ... 9 Nov 2009 17:44
Custom generic container class
I am trying to create a class named "tree_node" which can hold a label (char) and any type of data. I came up with the following code. template<typename T> struct node_traits { typedef T& reference; typedef T* pointer; }; template<typename T> struct node_traits<T*> { typedef T* reference; ... 13 Nov 2009 16:38
union members accessed with another member (whose data type requires less space)
int main() { union my_union{ int i; float f; }; my_union u; u.f = 2.0; std::cout << u.i; } why is int casted value of u.f not given? (the start address is the same for all the members). -Krishna. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.m... 9 Nov 2009 09:56
sizeof: Why parentheses needed when used with data types (when not required with variables)
Doesn't the context provide enough information (to the compiler) when it sees "sizeof int" and interpret it the same way as "sizeof x"? -Krishna. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] ... 10 Nov 2009 03:42
operator+() code for objects
I am trying to create a simple vector class with overloaded operators for assignment, +=, -=, +, *, etc My code for the overloaded operators worked OK, until I tried operator+ () The problem is that I can not return a local variable. This is fair enough, but I am sure that this used to work ok 10 years ago, when ... 8 Nov 2009 18:31
help on round robin tournament
I want to create a round robin tournament. The function receive a list (I've used a deque) and for now just prints to stdout the results (e.g. the round number and the schedule). If I wanted to provide the user a data structure that has all the miningful informations, what do you propose? Here my code (I'm a... 8 Nov 2009 21:50
Using (return val of) member function as default parameter of member function
On 6 Nov., 16:40, Djm <d...(a)jetzweb.de> wrote: Hello. Is it not possible to use (the return value of one member function) as default value for a parameter in another member function of the same class? For example In the code below I was suprised to get the compiler error "error: cannot call mem... 7 Nov 2009 10:43
When are data structures copied
Hi, In the following code snippet, when the <string, vector> pair is inserted into the map, is it necessary for the contents of the string and vector to be duplicated, or does this just shuffle pointers around? { string s(100, 'x'); vector<int> v(100); map<string, vector<int>> m; m.insert(make_pair(s, v));... 11 Nov 2009 01:14
First  |  Prev |  Next  |  Last
Pages: 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61