overload « Development « C Q&A

Home
C Q&A
1.assembly
2.buffer
3.Card
4.Cast
5.compile
6.console
7.const
8.constructor
9.database
10.Date
11.Debug
12.Design
13.Development
14.DLL
15.encrypt
16.enum
17.eof
18.Event
19.fork
20.Format
21.gcc
22.gdb
23.graph
24.graphics
25.gui
26.Holiday Event
27.image
28.IP
29.iterator
30.macro
31.makefile
32.malloc
33.Menu
34.mysql
35.network
36.openssl
37.operator
38.password
39.pipe
40.preprocessor
41.printf
42.pthread
43.Regular expression
44.scanf
45.semaphore
46.SerialPort
47.server
48.Socket
49.sql
50.SQLserver
51.sscanf
52.std
53.stdin
54.stdout
55.stl
56.strcmp
57.stream
58.switch
59.Template
60.thread
61.timer
62.unix
63.video
64.Virtual
65.visualstudio
66.winapi
67.windows
68.xml
C Q&A » Development » overload 

1. Does C support overloading?    stackoverflow.com

I just want to know if C supports over loading? As we use system functions like printf with different no of arguments. Help me out

2. How is implemented?    stackoverflow.com

C doesn't have (to the best of my knowledge) overloading or templates, right? So how can a set of type-agnostic functions with the same name exist in plain ol' C? The ...

3. Overloading classes problem...    bytes.com

4. Why do I need to overload =    bytes.com

John Doe Hi, I am trying to transform a class with some time consuming operation by adding a thread. To be able to pass data to thread I have declared a class ThreadParam as shown below : class CProvisioning { public: struct ThreadParam { ThreadParam(CProvisioning* a_pThis, const CString& a_strConfig, CString& a_strXmlOut): pThis(a_pThis), strConfig( a_strConfig ), strOut( a_strXmlOut ) {} CProvisioning* pThis; ...

6. Does the following construct qualify as overloading on return type ?    bytes.com

Nikhil.S.Ketkar@gmail.com Hi, Does the following construct qualify as overloading on return type ? If not, in what way ? I overloaded the type conversion operator and used pointers to member functions. Its pretty straightforward but I am sure I have missed as this is not supposed to be possible. Am I misunderstanding overloading ? Thanks, Nikhil // foo() overloads on both ...

7. overload or inherit    bytes.com

Hi, I would like to merge two class which have got 90% of same source code. But I don't know what to do. class A { int putLightOn () { switch(status) { case iAmOff : print "I am off" ; print "put me on!!!\n" ; } } } class B { int putLightOn () { switch(status) { case iAmOff : print ...

8. ambiguous overload when used with derived classes?    bytes.com

> int main( void ) { bar( baz( ), baz( ) ); // error: ambiguous overload The code generated here would be: template

9. overload resolution and conversion ops    bytes.com

xtrigger303@gmail.com Hi to all, I was reading Mr. Alexandrescu's mojo article and I've a hard time understanding the following. Let's suppose I have: //code struct A {}; struct B : A {}; struct C { operator A() const { return A(); } operator B() { return B(); } }; void F( A const & ) {} void F( B const & ...

10. Possible to require overloading of a non-pure method?    bytes.com

Hi all, I have a set of classes which implement the virtual constructor idiom. > I had a slicing problem which resulted when I forgot to override the clone() function in a derived class. > Is there something (other than documentation) that I can do to prevent this from happening again? >

11. inline overload operation question    bytes.com

Sorry for this stupid question, but i am lost. If i write an stringlib with += overload operators (no i do not, but my thing is much more complicated) , and i have to precalculate the strlen() -- as seen in the example here How do i solve this ? struct myStr { private: unsigned len; unsigned size; char string[100]; public: ...

12. Ambiguous overload problem    bytes.com

I'm not overloading return types so much as defining what happens when I cast the instance of Message to another datatype. Something to add to my original post- if I explicitly cast msg to const char *, it compiles. But for consistency and code length I would like to not have to do that.

13. deriving and 'overloading' of an attribute    bytes.com

Do keep in mind that a vector can have any dimensions you need. For example, if there are 12 ints in the vector, you could say that it is an array of [12] or an array [6][2] or an array [4][3] or an array [2][2][3]. You manage the dimensions by using iterators. You just need the one vector in the base ...

14. ambiguous overload    bytes.com

#include using namespace std; class Integer{ int i; public: Integer(int ii):i(ii){} const Integer operator+(const Integer& rv){ cout<<"1-operator+"<

15. Inheritance of overloaded vararg methods    bytes.com

RobertEstelle@gmail.com Hello, I've been banging my head against this problem for a couple hours now to no avail. I'm trying to make a descendant of a class that has overloaded methods with variable argument lists. The problem is, when my descendant class does the same, function resolution seems to stop there without looking at the base class. This happens both with ...

16. overloaded methods (error)    bytes.com

Latina Hi, I am doing a program using overloded operators but I am getting some error, Can some one help please. Here is my code: #include #include #include using namespace std; class Date { private: int mon; int day; int year; string m; public: friend istream& operator>>(istream& is, Date& d1); friend ostream &operator<<(ostream &os, const Date &d1); int operator-(Date); bool operator>(Date); ...

17. Inheritance, Overloading, and Candidate Lists    bytes.com

On 12 Oct, 22:18, Dan Noland Thanks, I just found a similar explanation in section 19.3.1 of Lippman and Lajoie. It seems strange that the shadowing is done by function name rather than function prototype, but this works. Do any language/compiler gurus know why this is the case? > YT, Dan Nolandhttp://nolandda.org/ It's a safety measure against very difficult ...

18. A Problem about istream ">>" overloading    bytes.com

P: n/a Colonel It seems that the problems have something to do with the overloading of istream operator ">>", but I just can't find the exact problem. // the declaration friend std::istream & operator>(std::istream & in, const Complex & a); // the methods correspond to the friend std::istream & operator>(std::istream & in, const Complex & a) { std::cout << "real: "; ...

19. Multiple inheritance/overloading ambiguity - is this behaviour intentional?    bytes.com

Adam Nielsen Hi everyone, I've run into yet another quirk with templates, which IMHO is a somewhat limiting feature of the language. It seems that if you inherit multiple classes, and those classes have two functions with the same name, this is an error - even when the functions take different parameters, and they would happily exist as overloaded functions if ...

20. Overloading problem    bytes.com

Hi, with this code: class Base { public: virtual int Simple(int i, int j); virtual int Simple(int i); virtual ~Base(); // make compiler happy }; class Derived : public Base { public: virtual int Simple(int i); }; int main(int argc, char* argv[]) { Derived b; b.Simple(1, 2); } Compiling with gcc 4.1.1 the call b.Simple(1,2) in main is not resolved, while ...

21. Is it possible to overload a member variable?    bytes.com

Goran wrote: Is it possible to overload a member variable? Yes; they are just two different variables. The working model here is that each class gives its data members scope and a storage slot. Deriving a class opens a new scope and a new storage region. Activity in that scope will look-up identifiers within its scope first, so the situation is ...

22. overload resolution clarification    bytes.com

class Base { public: virtual void f(int) { std::cout<<"base.f(int)\n";}; virtual void f(std::complex) { std::cout<<"derived.f \n"; }; }; class Derived : public Base { public : virtual void f(double) {std::cout<<"base.f(double)\n";}; }; int main() { Base b; //Line 1 Derived d; //Line 2 Base* pb = new Derived; //Line 3 pb->f(1.0f); //Line 4 return 0; } the above program is calling f(int) version, ...

23. Overloading matching weirdness    bytes.com

On 13 Maj, 23:35, MathStuf error: call of overloaded `LogSetVar(const char[8], unsigned int&, const char[5], unsigned int&, const String&)' is ambiguous note: candidates are: void LogSetVar(const char*, unsigned int, const ...

24. difference betweeen overloading and overriding    bytes.com

yashwant pinge wrote: #include using namespace std; > class base { public: void display() { } }; > class derived : public base { public: void display(int i ) { } }; > int main() { derived d; d.display(1); } > > can anyone tell me that display funcion in derived class is a overriding function or overloading function Neither. Overloading ...

25. operating overloading for "<"    bytes.com

26. overloading < and >    bytes.com

Hi all, I know it is possible to overload the operators and < in C++ but how can I do this. Assume I have a class Date with three int members, m_day, m_month and m_year. In the .cpp files I have defined the < and operators; bool Date::operator<(const Date& d) { return // this year < d year (m_year < d.m_year) ...

27. overloading vs. default argument question    bytes.com

So lets say I have this pretend function that compares a given serial number against the one true serial VALID_SERIAL: bool validateSerial(string serialNum) { if(serialNum == VALID_SERIAL) return true; else return false; } I want to add a function that does the same thing, but will also pad the given serialNum with a prefix of "0" if the original serialNum does ...

28. overloading of ","    bytes.com

Hi, I coded the following but It does not return what I expect, why? #include using namespace std; class Other { public: int i; Other(int x=1) { i = x; } Other *operator-() { return this;} Other &operator+ (Other t) { i += t.i; return *this; } Other &operator,(Other oth) { i = oth.i; return *this; } }; int main() ...

29. Overloaded delete does not calls the destructor??    bytes.com

On 6 Feb 2007 18:11:37 -0800, rohits123@gmail.com wrote: >I have an overload delete operator as below > >////////////////////////////////// >void operator delete(void* mem,int head_type) { > mmHead local_Head = CPRMemory::GetMemoryHead(head_type); > mmFree(&local_Head,(char *)mem); > CPRMemory::SetMemoryHeadAs(local_Head,head_type); >} >///////////////////// >void* operator new(size_t sz, int head_Type) { > char *mem; > mmHead local_Head = CPRMemory::GetMemoryHead(head_Type); > mem = mmAlloc(&local_Head,sz); > CPRMemory::SetMemoryHeadAs(local_Head,head_Type); > if(!mem) cout<<"Out of ...

30. Overloading vs RTTI    bytes.com

Chameleon What is better if you want upcasting in intermediate classes like below? Multiple Inheritance and Overloading or simply RTTI? RTTI wants time but MI and Overloading create big objects (because of virtual) and finally they need time too to access objects inside big object. (Examples looks complicated but are very simple) Paradigm #1: MI & Overloading ============================= //--------------- base classes ...

31. Overloading preincrement causing abnormal exit.    bytes.com

P: n/a Huck Phin OK, so I have looked and looked for something similar to my problem, and I cannot find one. I am writing a program for a HugeInteger, and I am attempting to overload the preincrement, postincrement, predecrement, and postdecrement operators. I realize that they are really all the same, and if I get one of the four operators ...

32. overloading    bytes.com

33. Method overloading and inheritance    bytes.com

Hi everyone, Given the code below, can anyone tell me: a) Is this normal behaviour ? b) If it is, what is the reason behind it ? I would expect the A::method(int) to be inherited by B. Compiler: gcc 4.1, Linux Thanks, Mihai ----------------------- #include class A{ public: virtual void method(int); }; class B: public A{ public: virtual void method(); ...

34. Overloading, hiding, :: and virtuals    bytes.com

Ole Nielsby wrote: I'm puzzed by this: .... ... I stumbled on the problem by accident, not because i was trying to push the limits of C++. Yes, I am not sure why the C++ gods thought that it was a good idea to hide inherited functions with the same name. But it is so. However, the "using" keyword can "unhide" ...

35. overloading subscript    bytes.com

Jerry Coffin re: overloading subscript In article <1157866759.637466.246860@b28g2000cwb.googlegroups .com>, murali.salem@gmail.com says... hello everybody... > how can i overload the subscript operator with more than one dimension... like [][][].... You can't do it directly -- you can either 1) overload some other operator (most often ()), or 2) you can overload operator[] to return some type that itself overloads operator[], and so ...

36. overloading    bytes.com

Let's assume I have a base class class X { }; and the the following classes inheriting class BX : public X { }; class AX : public X { }; and this class class MyClass { void DoSomething( AX* ); void DoSomething( BX* ); } and this code X* = ... MyClass c; c.DoSomething(X) Do I have to use a ...

37. overloaded global new/delete problem    bytes.com

Hi all, I am facing a peculiar problem. I am using a DLL which overloads the global new and delete as it uses its own memory manager. I am linking (implicitly) to this DLL. I am using another static library which has my CPP classes. Say SomeClass. >From my executable when I do SomeClass *sc = new SomeClass() <---- the CRT ...

38. overloading new/delete ....    bytes.com

hi I am trying to make some simple app to learn exception safety coding. I know that new and delete can throw bad_alloc but how can I force them to throw by a flag "change" at run time? I am overloading new, new[], delete and delete[], change is set to 1 then it calls the custom operators. If 0, it calls ...

39. Overloading error    bytes.com

andrew browning I am getting an istream overloading error that looks like this: error: no match for 'operator>>' in 'ins >> target->abrowning_rational::Rational::numerator' Below is the .h file: #ifndef RATIONAL #define RATIONAL #include namespace abrowning_rational{ class Rational{ public: //CONSTRUCTOR for the rational class Rational(); Rational(int a, int b); //CONSTANT MEMBER FUNCTIONS for the Rational class int getNum () const {return numerator;} ...

40. Is it possible to overload with return values?    bytes.com

Sunil Varma wrote:[color=blue] > No, it's not possible to overload functions based on its return type.[/color] There is one thing permitted by the language which resembles this -- covariant return types. It has more to do with overriding, though. In the case where a parent's member function is overridden, a "more specifically derived" (to coin a phrase?) return type -- that ...

41. Query regarding to overloading.    bytes.com

Uh, what is your question? Yes, overloaded functions are part of the C++ language. Yes, there is an algorithm for determining which overloaded function gets called, based on the arguments. The majority of cases, for properly designed functions, are simple and intuitive. Corner cases can get a bit abstruse -- if you're interested in the nitty gritty, google "Koenig lookup" (nods ...

42. Overloaded    bytes.com

Nagaraj wrote:[color=blue] > Can we overload main() function?[/color] 3.6.1p2 "An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation defined." 3.6.1p3 "The function main shall not be used (3.2) within a program. The linkage (3.5) of main is implementation defined. A program ...

43. About overloading    forums.devshed.com

Code: bool Student::operator!() { if(!canRegisterMore()) return true; else return false; } bool Student::registerCourse(Course course) //thise function expline abilety of register course but you should //the 1 can register more is true and 2 add currentcridet and number of cridet<10 { if (canRegisterMore() &&(currentcredits+ course.getNumberOfCridet())<=10) { cout << "You can register course "<

44. Overloading ofstream?    forums.devshed.com

45. how to overload <, >, ==    forums.devshed.com

Thanks wschweit! My compiler still rejects the == operator until I add 'const' before the first open brace in the definition. I don't know what to return for the > , < comparisons, I can't just return true or false, because what if the elements are equal? So I tried returning an int, but I guess that's not right because I ...

47. edit control overloaded?    forums.devshed.com

Quote: Originally Posted by miica thanks, and mitakeet, can you explain a bit about screen buffering? I don't know what's that. Under Windows, a specific window will receive a 'message' from the OS whenever it needs to be redrawn. Note that all the standard controls (edit controls, list boxes, buttons, combo boxes, etc) are just specialized forms of windows, generally child ...

48. Another class with overloading    forums.devshed.com

On first glance the one thing that jumps out at me are the entries from this series: if (sptr == "January") monthNumber = 1; sptr is a pointer to a character array. First, you should consider making that a const char *sptr instead of char *sptr, but that's minor here. The test fail, with the possible exception of an optimization that ...

49. Is this the proper way to overload ostream    forums.devshed.com

Code: #include using namespace std; class fraction { private: int numerator; int denominator; public: void assignFraction(int a, int b); int getNumerator() { return numerator; } int getDenominator () { return denominator; } void Input(istream& in); }; void fraction::assignFraction(int a, int b) { numerator = a; denominator = b; } ostream& operator << (ostream& out, fraction& s) { return out<

50. can't overload << (simple question)    forums.devshed.com

51. Error C2666 overloading << and >> for ostream and ofstream    forums.devshed.com

This assignment is killing me...glad it's almost the last one. Here's my new weird problem. I'm getting the error message "date.cpp(82) : error C2666: '<<' : 14 overloads have similar conversions.." Here are my code snippets: Date.h Code: #ifndef DATE_H #define DATE_H #include #include using namespace std; class Date { ;// define terminal I/O overloads which print a nice ...

52. WinMain can not be overloaded?    forums.devshed.com

53. ostream operaor.. overloading?    forums.devshed.com

54. How do I overload =.. code does not work properly.    forums.devshed.com

My constructor accepts a const char* and assigns it to the private array. I want the person to be able to do X="String Literal" and have the string literal assigned to X. In the class I have: S operator= (const char*); and the definition is: S S::operator= (const char* p) { S temp(p); return temp; } If one does: X asdf("temp"); ...

55. it is possible to overload return vals??    forums.devshed.com

Overloading on return values Its common to wonder why just scopes and argument lists? Why not return values? It seems at first that it would make sense to also mangle the return value with the internal function name. Then you could overload on return values, as well: void f(); int f(); This works fine when the compiler can unequivocally determine the ...

56. Overloading <<    forums.devshed.com

Hi, i am having trouble overloading the << operator for a class that I have written. Suppose my class is def as follows: Code: class Set { public: Set(int elem_num, int option) { for(int i=0; i

58. overload/specialize on cv qualifier    codeproject.com

Thanks for the info Andre and for fixing up the code. Unfortunately it was still a bit mangled, so I have updated the code just as a plain text paste - not pretty, but the preview looks like template params have been preserved etc. The target (object) pointer is stored internally in the Source as a void pointer (The source has ...

59. why not overload count    codeproject.com

60. == Overloading return expression    codeproject.com

@Optimus: x and y are the two operands of type Key for the == operator, so if one were to write the expression x == y what happens behing the scenes is that the function the_key() is called on both operands and the two values (here integers) are compared. Since this was probably an example on operator overloading they left out ...

61. Overloading == from a child class    codeproject.com

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.