Thanks a lot, mac11, for considering my problem and even trying different gcc versions. This is especially valuable for me since now I know a way to get my code compiled with correct debugging information.
I just installed gcc versions 4.5 and 4.1. When I compile using gcc 4.1 the debugging information seems correct (like in your post). However, the bug stays in version 4.5. Why would the developers have changed that?
Maybe...
User Profile
Collapse
-
Problem using gdb. Unwanted optimization?
Hi all,
I have a problem using gdb. I am using Eclipse-CDT as a frontend, but since this problem is obviously related to the gcc compiler or the gdb itself, I have reproduced it without Eclipse.
Sample Program
This small program should suffice to show my problem. I have saved this file as "main.cpp".
Code:#include<vector> #include <iostream> struct I{ std::vector<unsigned>
-
Thanks for your reply.
I am afraid, I didn't explain my problem well enough. So please let me try again:
I want to write a global function that does something. I want it to take one parameter of any type or class it can deal with. So I write a function template instead of a function, just like this:Code://first function template f template<typename T> void f(T obj){ /*do something*/ }
Leave a comment:
-
I am sorry I don't get it right away. What class should f be a member of?
Why exactly do I have to make it a member function?
And can I still call it the same way as the default version? (i.e., like: f(obj) )
Thanks for your time!
~<><~~~~~~~~ presenciaLeave a comment:
-
function template overloading
Hi all,
i would appreciate help with the following problem: Please consider the code
Code:#include <iostream> using namespace std; template<typename T> struct A{}; template<typename T> struct B: public A<T>{}; template<typename T> void f(T obj){ cout << "default\n"; } template<typename T> void f(A<T> obj){ cout << "special
-
Thanks Banfa,
I don't know why I didn't try just this before. It works, thank you. This thread is solved.
~<><~~~~~~~ presenciaLeave a comment:
-
presencia started a topic how do I access a member class of a class template from a template child classin Chow do I access a member class of a class template from a template child class
Hi all,
I got the following problem. I have two class templates, one inheriting from the other.
Code:template<typename T> struct M{ class A{}; }; template<typename T> class B:public M<T>{ A a; };
-
Wow, you opened my eyes.
I really was mistakenly thinking the vector contents were allocated on the stack. Thanks for pointing that out. - And for all your time answering me so elaborately. I will use references of vectors as parameters to my functions, just as you were proposing.
And you are right about writing short test programs rather then posting.
You guys helped me a lot. I think I am fit for the task now (at...Leave a comment:
-
I have found the boost::shared_p tr template to be quite similar to the handle classes proposed by weaknessforcats . Is that true? (I just read some of its documentation)
Would you think it is sensible for me to write
Code:boost::shared_ptr<vector<double> > v (new vector<double>(100000));
Code:v[5] //does that work? I don't
Leave a comment:
-
-
Thanks to both of you for all the discussion.
I haver learned some stuff (f.expl., that you can access vector elements from a vector pointer with "v_ptr[i]" , thought that was only true for C arrays), got a better feeling about things (about use of stack and heap). I have now read the Handle Class Article and I liked it, was quite easy to understand.
But all those concepts are not really new to me. I did think about...Leave a comment:
-
heap object question, and RAII advice request
Hi all,
I am still in the process of lerning how to write decent C++ code. I will appreciate any good advice or corrections. I have two questions, a technical one and one for advice for how to design my code.
1. I have read somewhere (can't remember, must have been some tutorial page) that objects allocated on the heap can only be accessed through pointers. Thus, for example
Code:vector<int> * v_ptr = new vector<
-
Error found
Hi everyone,
I believe to have found the error.
In line 31 it wrote
Code:data[half+index_data]=data_evens[index_data]-diff;
The line should have been
Code:data[half+ind
Leave a comment:
-
SIGSEGV on delete[] problem, recursive function calls
Hi everyone,
I have written a small program running fine until a Segmentation fault. Using a debugger I have localized the function the fault happens in. The Signal appears during a call to delete[] in the recursive function I have posted below. I have done some C coding before but I am fairly new to C++. I would really appreciate any help. I can't figure out where the problem is.
The function the SIGSEGV appears in is the following....
No activity results to display
Show More
Leave a comment: