Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

104 Neutral

About Nyarlath

  • Rank
  1. Nyarlath

    Indirect DLL loading conflict

    No, they are called from unrelated code. Looking at the modules loaded I have verified that both of the libraries are loaded, so I am now convinced that it is not a library loading problem, but a conflict between the two versions running in parallel. This is possible if they share some resources somewhere. Many thanks for your interest.
  2. Nyarlath

    Indirect DLL loading conflict

    No, they could not even, because they have to be located in the same folder as the application. If B2 is missing, the application refuse to start. (This is puzzling me because renaming the libs was the panacea of dll problems.)
  3. Dear all, I am developing an application A which links to third party libraries B (B1.lib and B1.dll) and C (C.lib, C.dll and B2.dll). B1 and B2 are different versions of the same library and export functions with the same names. The project compiles, links and starts, but I get runtime errors when I call functions declared in C. If I replace B1.dll with a copy of B2.dll (to verify that the wrong dll is being used), the calls of C are working, but obviously I get into trouble when I call functions of B1 directly. Why is C using B1 when it has been compiled linking to B2? Is there a way to force C to call the functions of B2 instead of B1? Many thanks
  4. Hi all, I don't come to compile a template definition which uses its unspecified template. When compiling C<T>, C alone is automatically replaced by C<T>. I don't see any logical issue in being able to use C as C<any T>, so probably I just need to know the right syntax. Here is some example code: template <template <typename T> class B> struct A { void func() { B<float> b; } }; template <typename T> struct F { }; template <typename T> struct C { void func() { A<F> af; // ok //A<C> ac; // invalid template argument for template parameter 'B', expected a class template //A<C<T> > at; // same error as above, and NOT what I want //A<C<typename> > act; // invalid template argument for template parameter 'B', expected a class template //A<template <typename T> C<T> > actt; // syntax error : ''template<'' } }; int main() { C<int> c; c.func(); } With Visual Studio 2005, the af declaration is "obviously" ok (not really needed in the example, just to show that analog things are working), ac is not. Thank you in advance!
  5. It's so easy to break the const correctness using pointer arithmetics! #include <iostream> int* ConstCast(const int* p) { int* a = 0; return p - a + a; } int* ConstCast2(const int* p) { int* a = 0; while (a < p) a++; // actually equivalent to "a += p-a" return a; } int main() { int i = 5; const int* p = &i; int* r = ConstCast(p); *r = 666; std::cout << i; // output 666 if "i" is declared non-const } To prevent the compilation of ConstCast we need that pointer subtractions which involve a const-pointer return a type that can not be added to a non-const pointer. To prevent the compilation of ConstCast2 we must forbid the comparison between const and non-const pointers; but we can always convert a non-const pointer to a const one before the comparison. So it is impossible to design pointer arithmetics without allowing trivial ways to break const correctness? PS1: This just mind training, I can not change the C++ specifications! PS2: I am sorry if this has been already discussed, but "pointer arithmetics" and "const correctness" are two topics so much discussed that I could not find anything on them together.
  6. Nyarlath

    Template Issue

    Quote:Original post by smc I have 'using namespace std ;' in the header. Should I use using namespace std in my code?
  7. Quote:Original post by yahn class H { private: std::list<int> mInts; public: std::list<int> *getInts(); }; - If you return a pointer to const, getInts() should also be a const member function. - If getInts() always returns the address of mInts, it should return a reference instead of a pointer (it can not be null and it can not be changed). class H { private: std::list<int> mInts; public: //const std::list<int>* getInts(){ return &mInts; } // bad const std::list<int>& getInts() const { return mInts; } // good };
  8. Nyarlath

    An, almost finished matrix class

    This is a very friendly explanation of the meaning of the matrix determinant. Quote:Original post by CodeCriminal Am i able to plug that code you posted directly into my class? Im not at home right now so i cant try it out. That was my intent, but I did not try it; it may contain some typo, but the indices should be correct since I copy-pasted them from the website I linked.
  9. Nyarlath

    problem with while in Matlab

    y and k are not defined in op=2*y+k+m if choice is equal to 2. You forgot to initialize them?
  10. Nyarlath

    An, almost finished matrix class

    Quote:Original post by CodeCriminal e = ( a - b + c - d ); return ( e.MatrixData[0][0] * ( e.MatrixData[1][1] * e.MatrixData[2][2] - e.MatrixData[2][1] * e.MatrixData[1][2] ) - e.MatrixData[1][0] * ( e.MatrixData[0][1] * e.MatrixData[2][2] - e.MatrixData[2][1] * e.MatrixData[0][2] ) + e.MatrixData[2][0] * ( e.MatrixData[0][1] * e.MatrixData[1][2] - e.MatrixData[1][1] * e.MatrixData[0][2] ) ); I don't know where do you have found this (where does MatrixData[3][3] come in?), but I would be very surprised if it is equal to: return ( e.MatrixData[0][0] * det(a) - e.MatrixData[1][1] * det(b) + e.MatrixData[2][2] * det(c) - e.MatrixData[3][3] * det(d) ); Since the calculation of the determinant of a 3x3 matrix is not trivial, you might use the much more performant "unrolled" formula (read here): template <typename Ty> Ty Matrix4<Ty>::Determinant( ) const { Ty* m = MatrixData; return m[0][3] * m[1][2] * m[2][1] * m[3][0]-m[0][2] * m[1][3] * m[2][1] * m[3][0]- m[0][3] * m[1][1] * m[2][2] * m[3][0]+m[0][1] * m[1][3] * m[2][2] * m[3][0]+ m[0][2] * m[1][1] * m[2][3] * m[3][0]-m[0][1] * m[1][2] * m[2][3] * m[3][0]- m[0][3] * m[1][2] * m[2][0] * m[3][1]+m[0][2] * m[1][3] * m[2][0] * m[3][1]+ m[0][3] * m[1][0] * m[2][2] * m[3][1]-m[0][0] * m[1][3] * m[2][2] * m[3][1]- m[0][2] * m[1][0] * m[2][3] * m[3][1]+m[0][0] * m[1][2] * m[2][3] * m[3][1]+ m[0][3] * m[1][1] * m[2][0] * m[3][2]-m[0][1] * m[1][3] * m[2][0] * m[3][2]- m[0][3] * m[1][0] * m[2][1] * m[3][2]+m[0][0] * m[1][3] * m[2][1] * m[3][2]+ m[0][1] * m[1][0] * m[2][3] * m[3][2]-m[0][0] * m[1][1] * m[2][3] * m[3][2]- m[0][2] * m[1][1] * m[2][0] * m[3][3]+m[0][1] * m[1][2] * m[2][0] * m[3][3]+ m[0][2] * m[1][0] * m[2][1] * m[3][3]-m[0][0] * m[1][2] * m[2][1] * m[3][3]- m[0][1] * m[1][0] * m[2][2] * m[3][3]+m[0][0] * m[1][1] * m[2][2] * m[3][3]; } PS: The Determinant member function should be const and do not need to return a const value.
  11. You can not do it because the elements in the map are saved in a tree sorted by key. This way you can find an element in O(log n) and insert in constant time when you know the right position. The elements can not be contiguous in memory because insert would take O(n) to shift all elements next to the inserted one (or reallocate all elements).
  12. Nyarlath

    c++ static vars in a class

    Quote:Original post by pavel989 so technically its being called like 3 times or w/e. Could that be the problem? No, if you have proper ifdef guards (your error message indicates you have not such problem). Instead of: // Window.h struct tagPOINT; class Window { static tagPOINT* lpPoint; }; // Window.cpp tagPOINT* Window::lpPoint = NULL; you could try with: // Window.h struct tagPOINT; class Window { static tagPOINT*& lpPoint() { static tagPOINT* point = NULL; return point; }; }; // Window.cpp empty! You need to replace lpPoint with lpPoint() everywhere, but it might solve your problem.
  13. Quote:Original post by ZahlmanWhich I'm guessing could be used to do evil things... I think not, the key remains const even in a non-const pair. Thank you all for the interest and for the link in particular. [EDIT] Quote:C++ Standard Library Defect Report List Simply requiring that keys be immutable is not sufficient, because the comparison object may indirectly (via pointers) operate on values outside of the keys. In fact this is another big problem! #include <set> struct S { S(const int& a) : m(&a) { } // autogenerated copy constructor and assignment op are fine bool operator < (const S& other) const { return *m < *other.m; } const int* m; }; int main() { int d[] = { 1, 2, 3 }; std::set<S> s(d, d + 2); // { 1, 2 } (abuse of implicit construction not relevant) d[0] = 4; // { 4, 2 } ofc allowed by VS05/08 and by ggc4 s.insert(d[2]); // { 3, 4, 2 } return 0; } At this point I think it does not make sense to forbid the former code, if this second problem is not solvable... trust the user or not, or?! [Edited by - Nyarlath on March 11, 2009 7:04:57 AM]
  14. The keys in the set must be const, so the values as well (in a set, the keys are the values themselves). So dereferencing a std::set<T>::iterator we should get a reference to a const object, because if we would change that object, its position in the set might need to be recomputed. As expected, on a mac + ggc, the std::set<T>::iterator is equal to the std::set<T>::const_iterator. Why it is not the case in Visual Studio? What do you think about that? Cheers! #include <set> int main() { int d[] = { 1, 2 }; std::set<int> s(d, d + 2); // { 1, 2 } *s.begin() = 4; // { 4, 2 } allowed by VS05/08, not by ggc4 s.insert(3); // { 3, 4, 2 } VS continues working "as expected" return 0; }
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!