Hi All, In below code when class a object is assigned to class b by returning object through factory method i observed assignment is not happening properly and after assignment still class b's object points to NULL object only. *cobj=rhs;//it gives NULL object However below statement works perfectly when b object cobj is directly assigned inside assignment operator . cobj=a::fact("a11")//it works fine can anybody let me know what is wrong with assignment approach ? I know there are other way as well (setter method) but i am curious to know in this circumstances how assignment is taken care. #include <iostream> …

Member Avatar
Member Avatar
+0 forum 4

Hi All, After compiling below code , I am getting below error. error: cannot convert a* to b* in assignment. it seems to be assignment doesn't work with pointers . Can anybody throw some light on this? i tried to use unique_ptr by transfering the ownership from a to b but it doesn't work. #include <iostream> #include <memory> using namespace std; class b ; class a { int a1 ; b *p; public: a(int x=0):a1(x){} void fun1() {cout<<a1;} }; class b { private: a *p; public: b (int x=0) { p= new a(x); //p1=new a(x); } b ( const b …

Member Avatar
Member Avatar
+0 forum 8

Hi All, in below class i wanted to have two friend function(overloading) one with default argument and other is without default argument. but during compilation it gives error. could you let me know how to fix (overload) this by not changing the function name , argument type or number of arguments. **error:** warning: void fun(int, int, int) is already a friend of class foo #include<iostream> using namespace std; class foo { public: friend void fun (int a, int b, int c); friend void fun (int a, int b, int c=20); }; int main() { return 1; }

Member Avatar
Member Avatar
+0 forum 1

i'm a newbie in java and i got an assignment to do and i don't know how to start ... the problem is: Write a program that will compute for the product of two numbers without using the * operator.. Sample Output: Enter Num1 :___ Enter num2 :___ Product is :___ hope you'll help me in this one :) :)

Member Avatar
Member Avatar
+0 forum 11

Hi, I have made a class and have an overloaded ostream operator method in it... However it tells me: "overloaded 'operator<<' must be a binary operator (has 3 parameters)." Can someone tell me how to fix this? Thank you! I have included some of my code: class Element { private: list<Element*> _children; char* _tag; int _value; public: ostream& operator<<(ostream& out, const Element& E); // (preordered traversal) }

Member Avatar
Member Avatar
+0 forum 4

Hi Guys, In below code you can see that i am able to execute the functionality of class a , inside the class b through composition and object of b can be used to call the methods declared inside the a class. #include <iostream> using namespace std; class a { int a1; public: a( int _a1=0):a1(_a1) { } void showname() { cout<<"class name a with value ="<<a1<<endl; } }; class b { public: b(a* cobj) : cobj(cobj) { cout<<"object initialization\n"; } void display() { cobj->showname(); } ~b () { cout<<"deleted the object of a"<<endl; delete cobj; } private: a *cobj; …

Member Avatar
Member Avatar
+0 forum 14

Hello. I have a list like this: mylist = [7, "+", 2, "+", 1] I want to take them out of the list inorder to run the operation and get the real result; something like this: result = 7 + 2 + 1 So the result variable will be set to 10. How can i do that?!

Member Avatar
Member Avatar
+0 forum 5

I have the following struct definition: struct finfo { string filename; long fsize; bool operator() (finfo i, finfo j){return (i.fsize > j.fsize);} } fstruct; And the following vector definition: vector<finfo> fdata; In the code I use the following statement to sort the vector elements by fsize: sort(fdata.begin(),fdata.end(),fstruct); This works perfectly well, but how can I sort by the field "filename" when i.fsize = j.fsize ? (The vector is filled by reading directory information, and putting the filenames and filesizes in the appropriate fields in the struct. If the filesize is equal I want to sort the files alphabetically by file …

Member Avatar
Member Avatar
+0 forum 3

Hey guys, Having some difficulties understanding why my OR || operator is not working... First part is BOOLEAN and it is working Second part is STRING and it is working, it returns the desired value What could it be ? <?php if(($oferte->isOrdered($oferte->CleanSapStyleNumbers($oferta->VBELN)) == false) || ($oferte->OfertaValida($oferte->CleanSapStyleNumbers($oferta->VBELN))->valabilitate == "VALABILA")): ?> some stuff <?php endif; ?>

Member Avatar
Member Avatar
+0 forum 4

Good morning, so I'm hoping anyone can help me, I'm planning this app, but I'm still searching if it's possible to be done or not. My question is the following: Imagine I'm in Spain, and I would like to get all the Network Operators in Spain. Is it possible to do that? Any help is appreciated.

Member Avatar
Member Avatar
+0 forum 2

can someone explain me how this operator work? i just need some hit to clearify my confusion on this... thanks

Member Avatar
Member Avatar
+0 forum 1

Hi, While executing below code i am getting error like "memory clobbered before allocated block" and due to this assignment is not happening. could you let me know what can be reason for the same. I do understand it is not good to use raw pointer but in current scenario i don't have other than any option. #include<iostream.h> using namespace std; class Derived1 { int *m_p; public: Derived1 (int *m_p):m_p(m_p){}; Derived1& operator =( const Derived1 &obj); void show()const {cout<<"integer address="<<(void*)m_p<<endl; cout<<"integer="<<*m_p<<endl; } ~Derived1(){ delete m_p; } }; Derived1& Derived1::operator=(const Derived1 &obj) { if (this!=&obj) { cout<<"We are Here"; int *orig …

Member Avatar
Member Avatar
+0 forum 4

I'm writing a program that works with two sets of numbers put into arrays. The program uses overloaded + and - operators. Array one = 2 7 4 2 9 7 Array two = 2 9 8 9 1 10 12 The output should be: For +, New Array = 2 7 4 9 10 8 1 12 For -, New Array = 7 4 2 7 My output is: Addition = 12 10 1 and Subtraction = 12 9 8 9 1 10 Here is the logic for the operators I used to write this code. The + operator: …

Member Avatar
Member Avatar
+0 forum 2

Dear Kind DaniWebbers, I am trying to overload the fstream operators (ofstream/ifstream), so that I can save a class to a 'Binary' file and also display it with cout. But the ways in which each need to be implemented is different. Please can you show me how to define different operators for each. Here is my test class: class CBase { public: //CBase(void) {}; CBase(int i = 0, float f = float(0.0), double d = double(0.0), char c = 'A') : iMyInt(i), fMyFloat(f), dMyDouble(d), cMyChar(c) {} ~CBase(void) {} int iMyInt; float fMyFloat; double dMyDouble; char cMyChar; friend std::ostream& operator<<(std::ostream& os, …

Member Avatar
Member Avatar
+0 forum 4

Hello, I have a particular set up of cast operators and constructors which is leading to a compile-time ambiguity error. I am wondering if somebody can explain why this is happening and what can be done to fix it. For example, here we have 2 classes: class A { int val; public: A(){val=0;} A(const A& o){val=o.val;} A(int i){val=i;} A&operator=(const A&o){val=o.val;return *this;} A&operator=(int i){val=i;return *this;} operator int(){return val;} }; class B { int val; public: B(int i){val=i;} operator A(){return A(val);} operator double(){return 0.0;} }; They work fine but don't really do anything at all. The purpose of the A operator in …

Member Avatar
Member Avatar
+0 forum 4

#include <iostream> using namespace std; template<class T> class MyClass { private: T data; public: MyClass(T data) { this->data = data; } }; template<class T> bool operator< (const MyClass<T> & a, const MyClass<T> & b) { return (a.data < b.data); } int main() { MyClass<int> x(1); MyClass<int> y(2); if(x < y) cout << "x is less than y!" << endl; return 0; } when i compile this it says T data is private, i know i needa declare some friend operators but not really sure how to do it :( can anyone help me please??

Member Avatar
Member Avatar
+0 forum 3

Hi All, I have doubt in my mind regarding declaration of cin and cout object . As per my understanding cin and cout both object are accessible in main then they shouldn't have protected.in below code snippet i have overloaded both input and output operator and while giving new name (ofstream obj) to user defined version of this operator , I am getting error like obj is protected and can't be accessed here. Anybody can suggest . #include<iostream> using namespace std; class overload { public: int var_a; overload (int fun_a=10): var_a(fun_a) {} friend ostream operator >> (ostream &output, overload &); …

Member Avatar
Member Avatar
+0 forum 4

1. #include<stdio.h> #include<conio.h> int main() int a=10; printf("%d%d%d",a,a++,++a); getch(); return 0; } o/p:12 11 11 #include<stdio.h> #include<conio.h> int main() { double a=5.2; if(a==5.2) printf("equal"); else if(a<5.2) printf("less"); else printf("high"); getch(); } o/p: less Can any one give me explanation for the above outputs.....

Member Avatar
Member Avatar
+0 forum 23

I've been reading through this introductory book on Python, and I've been following along fairly well. Compared to C++, Python seems to make more sense to me. That is, until I reached a section on Logical Operators. I don't completely understand what I just typed in to IDLE, and the results that were returned. Here's what I read: Python provides three logical operators: and, or, and not. Both and and or use short-circuit logic and return the operand that determined the result—they do not return a Boolean (unless they actually have Boolean operands). Let’s see what this means in practice: …

Member Avatar
Member Avatar
+0 forum 5

The foll code gives o/p as 2310103 28 Now my doubt is why here 10 is printed two times although i m passing t=6 for the d parameter?? #include <stdio.h> #include <string.h> int f(int a, int b, int c,int d,int e) { printf("%d%d%d%d%d \n",a,b,c,d,e); return a+b+c+d+e; } main() { int t; printf("%d",f(2,(1,(2,(3))),t=10,t=6,3),6); }

Member Avatar
Member Avatar
-1 forum 4

Hi, I've been learning about the std::copy function in the <algorithm> header and I'm stuck on this exercise that I gave my self. Let's see the code snippet first: #include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; ostream& operator<<(ostream& os, const int p_val) { os.put( p_val*2); return os; } int main(/*const int argc,const char* const argv[]*/) { std::vector<int> myVector = {34,54,43,2,7,87}; std::copy(myVector.begin(), myVector.end(), ostream_iterator<int>(std::cout, " ")); cin.get(); return 0; } Basically what I'm trying to achieve is: I have a vector full of integers. I want to print the mutiply of 2 of these integers to std::cout …

Member Avatar
Member Avatar
+0 forum 2

int m= i++ || ++j && k--; where i=2, j=3, amd k=5; acooridng to me, it will be executed left to right and then values of m=1, i=3, j=3 and k=5. but i have seen that precednace of && is more than || , than so how this expression is parenthezed by compiler to execute it ? as it goes to i++, and since it is non-zero , then it dont need to check after this, so stoped there. (this is what i thought before reading that precdance of && is more than || ). so what is wrong here …

Member Avatar
Member Avatar
+0 forum 14

I have two containers with the type of *A* A<string, double> s1; A<string, bool> s2; So I wrote the *A* class with the necessary functions and I used a template<class T, class E> for it. It has a function that returns a value of *E*, in my case, it returns a double which I'm trying to compare to another double. I'm supposed to overload the < operator for that, but I have no idea how to do that. 4.5 < s1.at("a"); s1.at("a"); returns 1.5, so it's false. I need it to return true. I thought since they are both double …

Member Avatar
Member Avatar
+0 forum 1

Pk, so here's the code I'm running for a checkboxlist object public void regSubjects(object sender, EventArgs e) { int courseCount = 0; for (int i = 0; i < coursesFound.Items.Count; i++) { if (coursesFound.Item[i].Selected) coursesCount++; } if ((courses < 4) && (courses > 6)) clabel.Text = string.Format("Choose between 4 - 6 subjects"); } Wierd thing is, if have only one condition in my final if, it works fine, if i have both, it doesn't pick it up, even if I nest the two conditions in their own if, it doesn't pick up on the error, just ignores it. Viusal Studio …

Member Avatar
Member Avatar
+0 forum 7

code part1: name1="rahul" name2="rahul" code part2: name1=[1,2,3] name2=[1,2,3] If I run the following code: print name1 is name2 I get "True" for code part1 and I get "False" for code part2 why? why the "reference" is same for name1 and name2 in "code part1" and different for name1 and name2 in "code part2??

Member Avatar
Member Avatar
+0 forum 2

I'm making a class for boolean expressions, a simpler version of bool. I need three operators, one for AND, one for OR and one for NOT. I can easily make **+** for OR, by overloading, but how can i declare **.** for AND and **'** for NOT? Can i even do this? Thanks in advance P.S, i'm a beginner :)

Member Avatar
Member Avatar
+0 forum 3

I am just learning Xpath. How to mix 2 or more xpath validtions into a single line. On my page, I have 2 different tables under hthe //body tag. I want to validate two td s that exist on these 2 different tables. IsElementPresent is my own method. It uses Xpath. field.IsElementPresent("//td[text()='End']"); field.IsElementPresent("//span[text()='variables']"); I tried [//td[text()='End'] and //span[text()='variables'] ]. This is failed.

Member Avatar
Member Avatar
+0 forum 1

I have been told it is good to overload the stream extraction operator to load data from a file. Would I simple use this in my class: friend ifstream &operator>>( ifstream &input, Class &C ) { input >> C.variable1 >> C.variable2 >> C.variable3; return input; } What are the advantages of overloading the stream extraction operator to read data from a file? Also I am confused what to do in main. At the moment to read in the data I have for example: ifstream fin; fin.open("filename.txt"); if(fin.good()) { object1 = new Class[10]; for (int i=0; i<10; i++) { fin >> …

Member Avatar
Member Avatar
+0 forum 7

---------------------------------------------TSet.h------------------------------------------------------ #include <iostream> using namespace std; template <class V> class TSet { public: TSet(); TSet(int size); ~TSet(); void add(V new_item); void remove(V item_to_remove); int num_of_items(); bool isFull(); bool is_item_in_set(V item); friend bool operator==(const TSet<V>& left, const TSet<V>& right); friend bool operator!=(const TSet<V>& left, const TSet<V>& right); friend ostream& operator<<(ostream& outs,const TSet<V>& list); private: V *item_list; int size_of_list; int current_size; }; ----------------------------------------TSet.cpp----------------------------------------- #include <iostream> #include "TSet.h" using namespace std; template<class V> TSet<V>::TSet() : size_of_list(0), current_size(0) { item_list = new V[0]; } template<class V> TSet<V>::TSet(int size) : size_of_list(size), current_size(0) { item_list = new V[size]; } template<class V> TSet<V>::~TSet() { delete [] item_list; …

Member Avatar
+0 forum 0

Hi, I am just trying to do some program on arithmetic expression parsing. So i want to store my operator precedence table in the program somehow. I could use a multidimensional array, but that would be inefficient i guess. Another idea i have is to use a HashTable, where the keys will be integers spcifying the precedence order, and the value can be an array or better an arraylist which can have the elements with the same precedence. But still this will involve a lot of looping around as the precedence value, is the key and not the value. Does …

Member Avatar
Member Avatar
+0 forum 8

The End.