107 Topics

Member Avatar for
Member Avatar for Mozza314

I'm a little new to C++ templating, and I'm having trouble understanding this behaviour. Basically, I have a templated class, and I want to define the = operator between the class and the same class with any template parameter. The problem is that the overloaded version of the = operator …

Member Avatar for mike_2000_17
0
249
Member Avatar for embooglement

I'm trying to write a to string function that would use std::stringstream to convert the the instance data into a string, but haven't been able to get operator overloading to work with it. As soon as I define a new << operator, I get a bunch of ambiguity errors saying …

Member Avatar for embooglement
0
2K
Member Avatar for pc0019

Hi! I am using the Boost uBlas interface for matrices and I'd like to be able to create matrices with the following syntax (or similar): [CODE] typedef boost::numeric::ublas::matrix<double> Matrix; //for clarity Matrix mat = {[1,1,1],[2,2,2],[3,3,3]}; [/CODE] The actual matrix should be 3x3 and look like the following - 1,1,1 2,2,2 …

Member Avatar for vijayan121
0
112
Member Avatar for sbrohee

Hi everyone, I am quite new to C++ (coming from perl). As an exercise, I am currently trying to create a class to play with graphs. I have a class Node in which I overload the == operator (to test the equality between two nodes). At the moment, I consider …

Member Avatar for sbrohee
0
265
Member Avatar for crapgarden

[COLOR="Red"]3.2 - Defining and Differentiating Computation. [] vs ()[/COLOR] I'm trying to get a solid fix on how math computations work in C++ and how to declare their order, in particular with respect to ( ) operators. this adds to an array: [CODE] inventory[numItems++] = "armor".[/CODE] why don't I need …

Member Avatar for crapgarden
0
126
Member Avatar for Member 784453

I decided to just try and make a program that would identify what KIND of expression you entered, not even evaluate it. Just for it to say: “You entered an addition equation. ” when you enter an equation with a value, a plus sign, then another value … and so …

Member Avatar for Member 784453
0
117
Member Avatar for corby

hey guys/gals im havin a problem in my test.cpp file in line 65 where i have cout << date.print(); the compiler says: test.cpp: In member function âvoid Test::print() constâ: test.cpp:67: error: no match for âoperator<<â in âstd::cout << ((const Test*)this)->Test::date.Date::print()â where am i making a mistake because i have <iostream> …

Member Avatar for corby
0
2K
Member Avatar for DaveTran

[CODE] for (int i = 0; i < 10; ++i) { i > 5 ? MethodA(i) : MethodB(i); } [/CODE] When trying to do the above I get this error [I]Type of conditional expression cannot be determined because there is no implicit conversion between 'void' and 'void' [/I] Does this …

Member Avatar for DaveTran
1
1K
Member Avatar for urbangeek

the code is: [CODE] slen=strlen(str); for(count=0;count<=slen;count++) { flag=0; if((int)str[count]!=32) { for(count2=count+1;count2<=slen;count2++) { if(str[count]==str[count2]) { flag=1; break; } } if(flag==0) { ar[ar_count]=str[count]; ar_count++; } } }[/CODE] at line 5 the != operator working fine but when i put [ICODE]if(((int)str[count]>=65 && (int)str[count]<=90) || ((int)str[count]>=97 && (int)str[count]<=122))[/ICODE] it's not working.. if you've some …

Member Avatar for WaltP
0
163
Member Avatar for Falmarri

It's been about a year since I've used C++, and I'm having a weird error that I can't remember why it does this, or if there's actually something wrong. My destructor gets called twice when I declare my object via the first method, and only once (correctly) when it declare …

Member Avatar for webs1987
0
223
Member Avatar for Macbeth

Hi, coders. I have to overload operators +, *, =. Object L3(default "abc") must be smth like this "aabbcc"(operator*; double each symbol of the string). Then I must concatenate Object2 and Object3(operator+), and initialize Object1(operator = ). I have strange errors error C2296: '*' : illegal, left operand has type …

Member Avatar for Banfa
0
186
Member Avatar for jonyb222

Good afternoon Daniweb, I have a simple (and probably idiotic) problem today, I have a simplistic program that simulates a Train station, trains come in, they go into a stationDock and come out after a while. The stationDocks are an array of trains, either pointing to a train or being …

Member Avatar for jonyb222
0
3K
Member Avatar for corby

my compiler keeps saying that i have an operator error at lines 22 and 50. what did i do wrong??? plz help [CODE]#include <iostream> using namespace std; class Rectangle { public: Rectangle()/*rectangle constructor defaults the values for length, width, area, and perimeter to 1 and initializes five rectangle objects to …

Member Avatar for corby
0
111
Member Avatar for samarudge

Hi, What is the function/opperator to calculate a power with C# I tryed [code=c] powerof = anumber ^ anothernumber; [/code] and that clearly doesn't work (1^3 is 2, 2^3 is 1 etc.) How do I do it??? I looked under [icode]Math.[/icode] functions and there was nothing and I spent ages …

Member Avatar for ddanbe
1
178
Member Avatar for MooAndStuff

Hey guys, im having some trouble in finding what I should return with the [] operator overloading. Here is my implementation code: [CODE] template <typename L> L& List<L>::operator[](int index) throw (ListException) { if (index >= length || index < 0) { throw ("In function: operator[]: index >= length or < …

Member Avatar for jonsca
0
101
Member Avatar for sumit21amig

How can i maintain operator's precedence order while overloading "+" and "*" in a class? e.g. I want same result on the calculation of following objects: d=a+b*c; d=c*a+b; Please help! Also tell me why simple constructor is able to call static data in a class?

Member Avatar for Geekitygeek
0
133
Member Avatar for Salem

This is a catalogue of some experiments on just two aspects of undefined behaviour. This was inspired by yet another long bout of explanation in a recent thread, so I thought it was time to dust off a bunch of compilers, and compare. This is the test code. [code] #include …

Member Avatar for frk
4
578

The End.