operator-overloading

Implicit cast doesnt work for BOOST_STRONG_TYPEDEF and BOOST_SPIRIT_DEBUG_NODE

无人久伴 提交于 2019-12-24 10:58:39
问题 I have defined a boost::spirit::qi rule: boost::spirit::qi::rule<Iterator, Identifier()> id; where Identifier is defined by: BOOST_STRONG_TYPEDEF(std::string, Identifier) but when I use BOOST_SPIRIT_DEBUG_NODE(id); It fails to compile with following error: boost_1_51_0/boost/spirit/home/support/attributes.hpp:1203: error: no match for 'operator<<' in 'out << val' and it lists the overloaded operators of ostream. Knowing that BOOST_STRONG_TYPEDEF defines a cast operator to the original type,

Thrust reduction and overloaded operator-(const float3&, const float3&) won't compile

心已入冬 提交于 2019-12-24 10:36:47
问题 I overload operators to have a vector space over float3 (and similar structs) in vectorspace.cuh : // Boilerplate vector space over data type Pt #pragma once #include <type_traits> // float3 __device__ __host__ float3 operator+=(float3& a, const float3& b) { a.x += b.x; a.y += b.y; a.z += b.z; return a; } __device__ __host__ float3 operator*=(float3& a, const float b) { a.x *= b; a.y *= b; a.z *= b; return a; } // float4 __device__ __host__ float4 operator+=(float4& a, const float4& b) { a.x

Operator 'overloading' equivalent with #define in C/Objective-C [duplicate]

南楼画角 提交于 2019-12-24 10:19:53
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Operator overloading in C If I have a struct: typedef struct myStruct { ... } myStruct; myStruct myStructAdd(myStruct a, myStruct b); I need something like this: #define myStruct a + myStruct b myStructAdd(a, b) // NOTE this code does NOT WORK. This is what the question is asking. To make this syntax valid: myStruct a; myStruct b; myStruct c = a + b; Is there any way to use a #define to do this? EDIT: I'm not

Binary Operator for Template Class Doesn't Resolve Implicit Conversion

你离开我真会死。 提交于 2019-12-24 10:00:00
问题 Consider the following classes, where the first is templated. Both are meant to hold a numeric value. template<typename T> struct foo { foo(T val) : val{ val } {} T val; }; struct bar { bar(double val) : val{ val } {} double val; }; I want to define a way to add these classes together to get a new one with a different value. template<typename T> foo<T> operator+(foo<T> a, foo<T> b) { return foo<T>(a.val + b.val); } bar operator+(bar a, bar b) { return bar(a.val + b.val); } When I use these

Issue with operator-> overloaded in VS2010

被刻印的时光 ゝ 提交于 2019-12-24 09:41:44
问题 I've implemented a small framework in C++ which I use in a course I give at college, to help students implement their homework. One of the most valuable classes of that framework, is a smart pointer class, which as you can imagine, it overloads the -> operator. Recently I upgraded from VS2008 to VS2010, and occasionally I get issues with the intellisense after typing the operator. Instead of showing the methods and fields available in the pointed data type, it shows the methods and fields of

Overload = operator for class that shall behave like matrix [duplicate]

大憨熊 提交于 2019-12-24 07:35:32
问题 This question already has answers here : How to overload array index operator for wrapper class of 2D array? (2 answers) Closed 6 years ago . I've got a template of a class that shall behave like matrix. So the usecase is something like: Matrix matrix(10,10); matrix[0][0]=4; //set the values for the rest of the matrix cout<<matrix[1][2]<<endl; When I set the values directly in the constructor, it works well, but when I want to use matrix[x][y]=z; I get error: lvalue required as left operand

Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'T' (or there is no acceptable conversion)

核能气质少年 提交于 2019-12-24 07:29:32
问题 I'm having problems with my friend function within my template class. For some reason it doesn't like the fact that I'm trying to use a variable that is type T in an operator overloading friend function. #include <iostream> #include <fstream> #include <string> template <typename T> class LL { struct Node { T mData; Node *mNext; Node(); Node(T data); }; private: Node *mHead, *mTail; int mCount; public: LL(); ~LL(); bool insert(T data); bool isExist(T data); bool remove(T data); void

How to make an overload operator which works with pointers

让人想犯罪 __ 提交于 2019-12-24 06:45:14
问题 As in the subject I need operator which will work with pointers so I do not have to call *a>*b but a>b . For example my operator << works with the pointers ok: friend ostream& operator<< (ostream &wyjscie, Para const* ex){ wyjscie << "(" << ex->wrt << ", " << ex->liczbaWystapien <<")"<< endl; return wyjscie; } but this one give me an error: friend bool operator> (Para const *p1, Para const *p2){ return p1->wrt > p2->wrt; } Error 1 error C2803: 'operator >' must have at least one formal

Operator overloading based on passed int?

北慕城南 提交于 2019-12-24 05:54:32
问题 I am trying to implement my own programing language in C++. When an error occours in my language (for example, during lexical analysis), an exception is thrown to be catched by the main function which then prints its message. The exception can be of different types: either SyntaxError , or FunctionError and so on, all based on the Error class so that they can all be catched even being of different types. Each sub class of errors anyway can generate different types of error, each one requiring

Overload operator| for fixed-size arrays?

蹲街弑〆低调 提交于 2019-12-24 04:19:34
问题 Consider the following: template <typename T> struct template_adapter_t {}; template <int N> struct foo_adapter_t { template <typename T> static foo_t<T, N> adapt(T const&); }; template <int N> template_adapter_t< foo_adapter_t<N> > foo(); template <typename Range, typename Adapter> auto operator|( Range const& range, template_adapter_t<Adapter>(*)()) -> decltype(Adapter::adapt(range)) { return Adapter::adapt(range); } (So, what is going on here... I have a 'dummy' class, template_adapter_t ,