Search Results

Search found 2508 results on 101 pages for 'ternary operator'.

Page 20/101 | < Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >

  • Versant OQL Statement with an Arithmetic operator

    - by Pascal
    I'm working on a c# project that use a Versant Object Database back end and I'm trying to build a query that contains an arithmetic operator. The documentation states that it is supported but lack any example. I'm trying to build something like this: SELECT * FROM _orderItemObject WHERE _qtyOrdered - _qtySent > 0 If I try this statement in the Object Inspector I get a synthax error near the '-'. Anyone has an example of a working VQL with that kind of statement? Thanks

    Read the article

  • new operator overwriting an existing object

    - by dvpdiner2
    I have a custom FastStack class, implemented as a fixed size array and an index into that array. In my copy constructor, I allocate the array and then assign each object from the copy's array into the new array. There's some refcounting in the objects on the stack, hence assignment is used rather than a simple copy. The problem is that when allocating the array, it sometimes overwrites part of the other stack's array. As can be expected, this leads to eventual segmentation faults when that data is dereferenced. class FastStack { private: int m_size, m_ptr; ObjectRef* m_stack; public: FastStack(int size) : m_size(size), m_ptr(-1) { m_stack = new ObjectRef[m_size]; } FastStack(const FastStack& copy) : m_size(copy.m_size), m_ptr(copy.m_ptr) { long a = (long)copy.m_stack[0]; m_stack = new ObjectRef[m_size]; if ((long)copy.m_stack[0] != a) fprintf(stderr, "\nWe have a serious problem!\n\n"); for (int i = 0; i <= m_ptr; i++) m_stack[i] = copy.m_stack[i]; } ~FastStack() { delete[] m_stack; } }; class ObjectRef { private: DataObj* m_obj; public: ObjectRef() : m_obj(0) { } ObjectRef(DataObj* obj) : m_obj(obj) { if (m_obj) m_obj->addRef(); } ObjectRef(const ObjectRef& obj) : m_obj(obj.m_obj) { if (m_obj) m_obj->addRef(); } ~ObjectRef() { if (m_obj) m_obj->delRef(); } ObjectRef& operator=(DataObj* obj) { if (obj) obj->addRef(); if (m_obj) m_obj->delRef(); m_obj = obj; return *this; } ObjectRef& operator=(const ObjectRef& obj) { if (obj.m_obj) obj.m_obj->addRef(); if (m_obj) m_obj->delRef(); m_obj = obj.m_obj; return *this; } }; I see that "We have a serious problem!" line shortly before a segfault, and stepping through it with gdb I can see that one of the ObjectRefs created by new has the same address as the other stack's array. My first instinct is to say that new should never be allocating memory that is already in use, but that clearly seems to be the case here and I am at a complete loss as to what can be done. Added: At the time that I see this happen, m_size = 2 and m_ptr = 0.

    Read the article

  • How to user IN operator in Linq?

    - by Umapathy
    Query: Select * from pu_Products where Part_Number in ('031832','027861', '028020', '033378') and User_Id = 50 and Is_Deleted = 0 The above mentioned query is in SQL and i need the query might be converted into Linq. Is there any option using the "IN" operator in Linq?. can you convert above mentioned query into Linq?

    Read the article

  • How to use the IN operator in linq

    - by Hallaghan
    I'm querying a view and filtering the results with a column named status. I'd like to query it so I can search for rows with different status, by using the IN operator as I'd do in SQL. As so: SELECT * FROM VIEW WHERE Status in ('....', '.....') How can I achieve this?

    Read the article

  • any stl/boost functors to call operator()

    - by Voivoid
    template <typename T> struct Foo { void operator()(T& t) { t(); } }; Is there any standart or boost functor with the similar implementation? I need it to iterate over container of functors: std::for_each(beginIter, endIter, Foo<Bar>()); Or maybe there are other way to do it?

    Read the article

  • Regarding address operator C/C++

    - by iSight
    Hi, What does address operator mean. say in the method below. what should be passed in the method as parameter value of integer or the address of an integer variable. void func1(int&)// method declaration void func1(int& inNumber)//method definition { //some code }

    Read the article

  • C++ operator ','

    - by user286215
    what is result of operator ',' by standard? Last argument? in code like this, for example: int a = 0; int b = 1; while(a,b); or using it like this is not allowed? MSVS thiks that result is b, is it true?

    Read the article

  • % operator for time calculation

    - by Chris
    I am trying to display minutes and seconds based on a number of seconds. I have: float seconds = 200; float mins = seconds / 60.0; float sec = mins % 60.0; [timeIndexLabel setText:[NSString stringWithFormat:@"%.2f , %.2f", mins,seconds]]; But I get an error: invalid operands of types 'float' and 'double' to binary 'operator%' And I don't understand why... Can someone throw me a bone!?

    Read the article

  • Templated << friend not working when in interrelationship with other templated union types

    - by Dwight
    While working on my basic vector library, I've been trying to use a nice syntax for swizzle-based printing. The problem occurs when attempting to print a swizzle of a different dimension than the vector in question. In GCC 4.0, I originally had the friend << overloaded functions (with a body, even though it duplicated code) for every dimension in each vector, which caused the code to work, even if the non-native dimension code never actually was called. This failed in GCC 4.2. I recently realized (silly me) that only the function declaration was needed, not the body of the code, so I did that. Now I get the same warning on both GCC 4.0 and 4.2: LINE 50 warning: friend declaration 'std::ostream& operator<<(std::ostream&, const VECTOR3<TYPE>&)' declares a non-template function Plus the five identical warnings more for the other function declarations. The below example code shows off exactly what's going on and has all code necessary to reproduce the problem. #include <iostream> // cout, endl #include <sstream> // ostream, ostringstream, string using std::cout; using std::endl; using std::string; using std::ostream; // Predefines template <typename TYPE> union VECTOR2; template <typename TYPE> union VECTOR3; template <typename TYPE> union VECTOR4; typedef VECTOR2<float> vec2; typedef VECTOR3<float> vec3; typedef VECTOR4<float> vec4; template <typename TYPE> union VECTOR2 { private: struct { TYPE x, y; } v; struct s1 { protected: TYPE x, y; }; struct s2 { protected: TYPE x, y; }; struct s3 { protected: TYPE x, y; }; struct s4 { protected: TYPE x, y; }; struct X : s1 { operator TYPE() const { return s1::x; } }; struct XX : s2 { operator VECTOR2<TYPE>() const { return VECTOR2<TYPE>(s2::x, s2::x); } }; struct XXX : s3 { operator VECTOR3<TYPE>() const { return VECTOR3<TYPE>(s3::x, s3::x, s3::x); } }; struct XXXX : s4 { operator VECTOR4<TYPE>() const { return VECTOR4<TYPE>(s4::x, s4::x, s4::x, s4::x); } }; public: VECTOR2() {} VECTOR2(const TYPE& x, const TYPE& y) { v.x = x; v.y = y; } X x; XX xx; XXX xxx; XXXX xxxx; // Overload for cout friend ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString) { os << "(" << toString.v.x << ", " << toString.v.y << ")"; return os; } friend ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString); friend ostream& operator<<(ostream& os, const VECTOR4<TYPE>& toString); }; template <typename TYPE> union VECTOR3 { private: struct { TYPE x, y, z; } v; struct s1 { protected: TYPE x, y, z; }; struct s2 { protected: TYPE x, y, z; }; struct s3 { protected: TYPE x, y, z; }; struct s4 { protected: TYPE x, y, z; }; struct X : s1 { operator TYPE() const { return s1::x; } }; struct XX : s2 { operator VECTOR2<TYPE>() const { return VECTOR2<TYPE>(s2::x, s2::x); } }; struct XXX : s3 { operator VECTOR3<TYPE>() const { return VECTOR3<TYPE>(s3::x, s3::x, s3::x); } }; struct XXXX : s4 { operator VECTOR4<TYPE>() const { return VECTOR4<TYPE>(s4::x, s4::x, s4::x, s4::x); } }; public: VECTOR3() {} VECTOR3(const TYPE& x, const TYPE& y, const TYPE& z) { v.x = x; v.y = y; v.z = z; } X x; XX xx; XXX xxx; XXXX xxxx; // Overload for cout friend ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString) { os << "(" << toString.v.x << ", " << toString.v.y << ", " << toString.v.z << ")"; return os; } friend ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString); friend ostream& operator<<(ostream& os, const VECTOR4<TYPE>& toString); }; template <typename TYPE> union VECTOR4 { private: struct { TYPE x, y, z, w; } v; struct s1 { protected: TYPE x, y, z, w; }; struct s2 { protected: TYPE x, y, z, w; }; struct s3 { protected: TYPE x, y, z, w; }; struct s4 { protected: TYPE x, y, z, w; }; struct X : s1 { operator TYPE() const { return s1::x; } }; struct XX : s2 { operator VECTOR2<TYPE>() const { return VECTOR2<TYPE>(s2::x, s2::x); } }; struct XXX : s3 { operator VECTOR3<TYPE>() const { return VECTOR3<TYPE>(s3::x, s3::x, s3::x); } }; struct XXXX : s4 { operator VECTOR4<TYPE>() const { return VECTOR4<TYPE>(s4::x, s4::x, s4::x, s4::x); } }; public: VECTOR4() {} VECTOR4(const TYPE& x, const TYPE& y, const TYPE& z, const TYPE& w) { v.x = x; v.y = y; v.z = z; v.w = w; } X x; XX xx; XXX xxx; XXXX xxxx; // Overload for cout friend ostream& operator<<(ostream& os, const VECTOR4& toString) { os << "(" << toString.v.x << ", " << toString.v.y << ", " << toString.v.z << ", " << toString.v.w << ")"; return os; } friend ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString); friend ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString); }; // Test code int main (int argc, char * const argv[]) { vec2 my2dVector(1, 2); cout << my2dVector.x << endl; cout << my2dVector.xx << endl; cout << my2dVector.xxx << endl; cout << my2dVector.xxxx << endl; vec3 my3dVector(3, 4, 5); cout << my3dVector.x << endl; cout << my3dVector.xx << endl; cout << my3dVector.xxx << endl; cout << my3dVector.xxxx << endl; vec4 my4dVector(6, 7, 8, 9); cout << my4dVector.x << endl; cout << my4dVector.xx << endl; cout << my4dVector.xxx << endl; cout << my4dVector.xxxx << endl; return 0; } The code WORKS and produces the correct output, but I prefer warning free code whenever possible. I followed the advice the compiler gave me (summarized here and described by forums and StackOverflow as the answer to this warning) and added the two things that supposedly tells the compiler what's going on. That is, I added the function definitions as non-friends after the predefinitions of the templated unions: template <typename TYPE> ostream& operator<<(ostream& os, const VECTOR2<TYPE>& toString); template <typename TYPE> ostream& operator<<(ostream& os, const VECTOR3<TYPE>& toString); template <typename TYPE> ostream& operator<<(ostream& os, const VECTOR4<TYPE>& toString); And, to each friend function that causes the issue, I added the <> after the function name, such as for VECTOR2's case: friend ostream& operator<< <> (ostream& os, const VECTOR3<TYPE>& toString); friend ostream& operator<< <> (ostream& os, const VECTOR4<TYPE>& toString); However, doing so leads to errors, such as: LINE 139: error: no match for 'operator<<' in 'std::cout << my2dVector.VECTOR2<float>::xxx' What's going on? Is it something related to how these templated union class-like structures are interrelated, or is it due to the unions themselves? Update After rethinking the issues involved and listening to the various suggestions of Potatoswatter, I found the final solution. Unlike just about every single cout overload example on the internet, I don't need access to the private member information, but can use the public interface to do what I wish. So, I make a non-friend overload functions that are inline for the swizzle parts that call the real friend overload functions. This bypasses the issues the compiler has with templated friend functions. I've added to the latest version of my project. It now works on both versions of GCC I tried with no warnings. The code in question looks like this: template <typename SWIZZLE> inline typename EnableIf< Is2D< typename SWIZZLE::PARENT >, ostream >::type& operator<<(ostream& os, const SWIZZLE& printVector) { os << (typename SWIZZLE::PARENT(printVector)); return os; } template <typename SWIZZLE> inline typename EnableIf< Is3D< typename SWIZZLE::PARENT >, ostream >::type& operator<<(ostream& os, const SWIZZLE& printVector) { os << (typename SWIZZLE::PARENT(printVector)); return os; } template <typename SWIZZLE> inline typename EnableIf< Is4D< typename SWIZZLE::PARENT >, ostream >::type& operator<<(ostream& os, const SWIZZLE& printVector) { os << (typename SWIZZLE::PARENT(printVector)); return os; }

    Read the article

  • C++ brain teaser

    - by mxp
    I recently refactored code like this (MyClass to MyClassR). class SomeMember { long m_value; public: SomeMember() : m_value(0) {} SomeMember(int a) : m_value(a) {} SomeMember(int a, int b) : m_value(a+b) {} }; class MyClass { SomeMember m_first, m_second, m_third; public: MyClass(const bool isUp, const int x, const int y) { if (isUp) { m_first = SomeMember(x); m_second = SomeMember(y); m_third = SomeMember(x, y); } else { m_first = SomeMember(y); m_second = SomeMember(x); m_third = SomeMember(y, x); } } }; class MyClassR { SomeMember m_first, m_second, m_third; public: MyClassR(const bool isUp, const int x, const int y) : m_first(isUp ? x : y) , m_second(isUp ? y : x) , m_third(isUp ? x, y : y, x) { } }; What is the error, why does it compile (at least VC6 with warning level 3 doesn't complain) and what is the right way of doing it? I (assume) I already have all these answers but I think it's and interesting problem to share.

    Read the article

  • += Overloading in C++ problem.

    - by user69514
    I am trying to overload the += operator for my rational number class, but I don't believe that it's working because I always end up with the same result: RationalNumber RationalNumber::operator+=(const RationalNumber &rhs){ int den = denominator * rhs.denominator; int a = numerator * rhs.denominator; int b = rhs.numerator * denominator; int num = a+b; RationalNumber ratNum(num, den); return ratNum; } Inside main //create two rational numbers RationalNumber a(1, 3); a.print(); RationalNumber b(6, 7); b.print(); //test += operator a+=(b); a.print(); After calling a+=(b), a is still 1/3, it should be 25/21. Any ideas what I am doing wrong?

    Read the article

  • Type casting Collections using Conversion Operators

    - by Vyas Bharghava
    The below code gives me User-defined conversion must convert to or from enclosing type, while snippet #2 doesn't... It seems that a user-defined conversion routine must convert to or from the class that contains the routine. What are my alternatives? Explicit operator as extension method? Anything else? public static explicit operator ObservableCollection<ViewModel>(ObservableCollection<Model> modelCollection) { var viewModelCollection = new ObservableCollection<ViewModel>(); foreach (var model in modelCollection) { viewModelCollection.Add(new ViewModel() { Model = model }); } return viewModelCollection; } Snippet #2 public static explicit operator ViewModel(Model model) { return new ViewModel() {Model = model}; } Thanks in advance!

    Read the article

< Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >