Mingw not complaining

This is a discussion on Mingw not complaining within the C++ Programming forums, part of the General Programming Boards category; I'm using mingw gcc(3.xxx) compiler. In the following code I pass a variable 'q' as 'const' but I later use ...

  1. #1
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203

    Unhappy Mingw not complaining

    I'm using mingw gcc(3.xxx) compiler. In the following code I pass a variable 'q'as 'const' but I later use its private members in the '>>'operator (in the same function) which obviously modify it. but the compiler did'nt complain and the programm compiled. Later during execution when I used the '>>' operation, the program halted when it reached that point. Even though I understood the error and corrected it, what I don't understand is why the compiler did'nt yell at me.
    Does someone have a clue?

    Code:
    //quaternion.h
    //no #include iostream as it is included in the main file.
    using namespace std; //for the istream and ostream
    
    class Quaternion{
    private:
        long double a, b, c, d;
    public:
        Quaternion(long double aa=0, long double bb=0,
                   long double cc=0, long double dd=0):a(aa), b(bb), c(cc), d(dd){}
        virtual ~Quaternion(){}
        friend ostream& operator <<(ostream& out, const Quaternion& q){
            out<<q.a<<"+"<<q.b<<"i+"<<q.c<<"j+"<<q.d<<"k";
            return out;
        }
        friend istream& operator >>(istream& in, constQuaternion& q){
            in>>q.a>>q.b>>q.c>>q.d;//modifies q's members
            return in;
        }
        Quaternion operator +(const Quaternion q){
            return Quaternion(a+q.a, b+q.b, c+q.c, d+q.d);
        }
        Quaternion operator -(const Quaternion q){
            return Quaternion(a-q.a, b-q.b, c-q.c, d-q.d);
        }
        void set(long double aa=0, long double bb=0,
                 long double cc=0, long double dd=0){
            //blah blah
        }
        long double& operator [](unsigned int i){ //0 for 'a' component
           //blah blah
        }
        Quaternion operator *(const Quaternion& q){
            //blahblah
        }
    };
    Code:
    //main.cpp
    #include<iostream>
    #include"../quaternionfractal/quaternion.h"
    using namespace std;
    
    int main(){
    Quaternion x, y;
    cout<<"x :";
    [b]cin>>x; //when here the program halts and terminates without any complaining.
    cout<<"y :";
    cin>>y;
    cout<<"x   :"<<x<<"\n"
        <<"y   :"<<y<<"\n"
        <<"x*y :"<<x*y<<"\n"
        <<"y*x :"<<y*x<<"\n";
    return 0;[b]
    }

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Maybe you don't have all your compiler warnings on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  2. Free compiler for commercial development? (mingw?)
    By kook44 in forum Windows Programming
    Replies: 8
    Last Post: 01-07-2006, 08:32 AM
  3. compiling mingw to enable timeSetEvent
    By underthesun in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2005, 05:00 PM
  4. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 09:59 PM
  5. Convert Microsoft LIB to MingW compatible lib
    By tigs in forum Windows Programming
    Replies: 0
    Last Post: 07-20-2004, 06:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21