0

I recently started to study classes and operator overloading in C++, and wrote following Bignum class in order to pratice. Link: http://pastebin.com/cQNwRChx. It's not a final version, for example there is no exception handling and maybe it's not so effective, so I want to clarify some questions:

  1. This code is successfully compiled in MSVS 2010, but GNU C++ 4.4.1 says, that 'fft' was not declared in this scope in line 465.
  2. I use Fast Fourier transform to multiply numbers when the result is huge. Because of very slow standard complex numbers, I wrote my own implementation. In my opinion, these complex numbers should be hidden, because it's like a part of Lint implementation. So I declare it as a private nested class of Lint, and declare fft as a friend of Lint. Why it doesn't work in GNU?
  3. The debugger of MSVS shows, that constant ONE isn't a static constant. It's defined below, after Lint's definition.
  4. I would like to use class with int, unsigned int and etc. in expressions, and current version works fine, but also I want to have an opportunity to write something like this: if (a) ..., where a is Lint. But if I define implicit conversion to bool and write a+b, where a is int and b is Lint, there is an ambiguity. How can I solve this problem?

UPD. There is a simple pseudo-code without excess functions and definitions: http://pastebin.com/rauKQjtH.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
perlik
  • 93
  • 6
  • 4
    This is an interesting code but it’s completely out of scope for feedback here. Please create a **minimal, complete version** of the code that still exhibits the problem and remove any irrelevant code – people will be much more likely to look at it. – Konrad Rudolph Apr 12 '13 at 17:46
  • it compiles on g++ 4.6.3 without warnings... – iBrAaAa Apr 12 '13 at 18:11
  • this code compiles ok on gcc 4.7.1, also please have a look at http://stackoverflow.com/questions/7578682/why-should-i-overload-a-c-operator-as-a-global-function-stl-does-and-what-ar – joy Apr 12 '13 at 19:31
  • For question 4, use `explicit operator bool() const` if C++11 is allowed, otherwise google "Safe-Bool-Idiom". Also, you might find my [df.operators](https://github.com/d-frey/operators/) library useful (again if C++11 is an option, otherwise check out [Boost.Operators](http://www.boost.org/doc/libs/1_53_0/libs/utility/operators.htm)) – Daniel Frey Apr 12 '13 at 23:51

0 Answers0