Link to home
Start Free TrialLog in
Avatar of tjgquicken
tjgquicken

asked on

C++ compiler error

I'm getting the following error when I try to compile my C++ program, but I don't know what it means. Can anybody help me please?


g++  -g -I include  -c -o division.o src/division.cpp
/usr/include/c++/4.0.0/bits/stl_bvector.h: In member function void std::vector<bool, _Alloc>::_M_insert_range(std::_Bit_iterator, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag):
/usr/include/c++/4.0.0/bits/stl_bvector.h:554: error: expected unqualified-id before ( token
/usr/include/c++/4.0.0/bits/stl_bvector.h: In member function void std::vector<bool, _Alloc>::_M_fill_insert(std::_Bit_iterator, size_t, bool):
/usr/include/c++/4.0.0/bits/stl_bvector.h:901: error: expected unqualified-id before ( token
/usr/include/c++/4.0.0/bits/vector.tcc: In member function void std::vector<_Tp, _Alloc>::_M_fill_insert(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, size_t, const _Tp&):
/usr/include/c++/4.0.0/bits/vector.tcc:353: error: expected unqualified-id before ( token
/usr/include/c++/4.0.0/bits/vector.tcc: In member function void std::vector<_Tp, _Alloc>::_M_range_insert(__gnu_cxx::__normal_iterator<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, _ForwardIterator, _ForwardIterator, std::forward_iterator_tag):
/usr/include/c++/4.0.0/bits/vector.tcc:452: error: expected unqualified-id before ( token

Open in new window

Avatar of Infinity08
Infinity08
Flag of Belgium image

Can you show the code that these errors refer to (not just the line, but also the code around and especially before it)
Avatar of tjgquicken
tjgquicken

ASKER

This is the file that won't compile. It doesn't use the STL vector class at all.  I should note that when I remove the #include "biginteger.h", I don't get this error message any more.
#include <map>
 
#include "biginteger.h"
#include "division.h"
 
using std::invalid_argument;
 
bool divides( const BigInteger &a, const BigInteger& b ) {
  if( b.equalsZero( ) ) {
    throw invalid_argument("Cannot divide by zero.");
  }
 
  return (a % b).equalsZero( );
}
 
BigInteger gcd( const BigInteger &m, const BigInteger &n ) {
  if( n > m ) {
    return gcd(n, m);
  }
 
  if( n.equalsZero( ) ) {
    return BigInteger(m);
  }
  else {
    return gcd(n, m % n);
  }
}
 
/**
 * Solves ax + by = gcd(a,b) for integers a, b, x, y.
 * Pass addresses to store x, y.
 * Returns gcd(a,b).
 */
BigInteger linearGcd_iter( const BigInteger &a, const BigInteger &b, BigInteger &x, BigInteger &y ) {
	x = BigInteger(1);
	BigInteger g = BigInteger(a), v = BigInteger((long)0), w = BigInteger(b), q, s, t;
	while(!w.equalsZero( )) {
		q = longDivide(g, w, &t);
		s = x - (q * v);
 
		g = w;
		x = v;
		y = w;
		v = s;
		w = t;
	}
	y = (g - (a * x)) / b;
 
	return g;
}
 
/**
 * Solves ax + by = gcd(a,b) for integers a, b, x, y.
 * Pass addresses to store x, y.
 * Returns gcd(a,b).
 */
BigInteger linearGcd( const BigInteger &a, const BigInteger &b, BigInteger &x, BigInteger &y ) {
	if( b > a ) {
		return linearGcd(b, a, y, x);
	}
 
	if( divides(b, a) ) {
		x = BigInteger(1), y = BigInteger((long)0);
		return b;
	}
	else {
		BigInteger gcd, xPrime, yPrime;
		gcd = linearGcd(b, a % b, xPrime, yPrime);
		x = yPrime, y = xPrime - yPrime * (longDivide(a, b));
		return gcd;
	}
 
}
 
factor_map factor( const BigInteger& b ) {
  if( b.equalsZero( ) ) {
    throw invalid_argument("Cannot divide by zero.");
  }
  
  factor_map factorization;
  
  BigInteger current = BigInteger(b);
  if(current < ::ZERO) {
    factorization[ BigInteger(-1) ] = 1;
    current = current * -1;
  }
  
  std::vector< int > primes = sieveOfEratosthenes(b.toLong( ));
  while(current != ::ONE) {
    std::vector< int >::const_iterator iter = primes.begin( );
    while(!divides( BigInteger(*iter), current )) {
      ++iter;
    }
    
    cout << "\n" << *iter;
    current = current / *iter;
  }
  //	unfinished function
}

Open in new window

please show us "biginteger.h".
>> I should note that when I remove the #include "biginteger.h", I don't get this error message any more.

Then that should be an indication that there's something wrong with that header file ;)

Go through the file, and check the syntax. Are there any missing ;'s for example, or other obvious mistakes. If you can't find it, please post the header file in question like rendaduiyan already requested.
I thought about that, except I can't find any syntax problems in the biginteger.h file. Eclipse doesn't see any problems with it either, and it compiles fine (as does its corresponding .cpp file). Also, it still doesn't use the STL vector (neither does the .cpp file), so why would there be an error there?
#ifndef BIGINTEGER_H
#define BIGINTEGER_H
 
#include <iostream>
 
using std::ostream;
using std::cout;
using std::endl;
 
#include <deque>
 
#ifndef max
#define max(a,b) (((a)>(b))?(a):(b))
#endif
 
#ifndef min
#define min(a,b) (((a)<(b))?(a):(b))
#endif
 
#ifndef square
#define square(x) ((x)*(x))
#endif
 
// We assume base 10, for now.
#define BASE 10
 
class BigInteger {
 
  friend class BigIntegerTest;
 
  friend BigInteger operator+( const BigInteger&, const BigInteger& );
  friend void addDigits( const BigInteger&, const BigInteger&, BigInteger&, bool* );
 
  friend BigInteger operator-( const BigInteger& );
 
  friend BigInteger longMultiply( const BigInteger&, const BigInteger& );
  friend BigInteger karatsubaMultiply( const BigInteger&, const BigInteger& );
 
  friend BigInteger longDivide( const BigInteger&, const BigInteger&, BigInteger* );
 
  friend BigInteger join( const BigInteger&, const BigInteger& );
  friend bool objectEquals( const BigInteger&, const BigInteger& );
  friend BigInteger abs( const BigInteger& );
 
  friend ostream& operator<<( std::ostream&, const BigInteger& );
 
 public:
  BigInteger( );
  BigInteger( char[] );
  BigInteger( long );
  BigInteger( const BigInteger& );
 
  BigInteger diminishedRadixComplement( ) const;
  void shiftLeft( int );
  void shiftRight( int );
  bool equalsZero( ) const;
  int signum( ) const;
  int length( ) const;
  void trim( );
  BigInteger substring( int, int ) const;
  void objectPrint( ) const;
  void print( ) const;
  void abs( );
 
  long toLong( ) const;
 
 private:
  std::deque< short > digits;
 
 protected:
  bool isNegative;
 
};
 
// these should probably find their way into a namespace...
static const BigInteger ZERO = BigInteger(0L);
static const BigInteger ONE = BigInteger(1);
 
BigInteger operator+( const BigInteger&, const BigInteger& );
BigInteger operator+( const BigInteger&, const long& );
BigInteger operator+( const long&, const BigInteger& );
void addDigits( const BigInteger&, const BigInteger&, BigInteger&, bool* );
 
BigInteger operator-( const BigInteger& );
BigInteger operator-( const BigInteger&, const BigInteger& );
BigInteger operator-( const BigInteger&, const long& );
BigInteger operator-( const long&, const BigInteger& );
 
BigInteger operator*( const BigInteger&, const BigInteger& );
BigInteger operator*( const BigInteger&, const long& );
BigInteger operator*( const long&, const BigInteger& );
BigInteger longMultiply( const BigInteger&, const BigInteger& );
BigInteger karatsubaMultiply( const BigInteger&, const BigInteger& );
BigInteger operator^( const BigInteger&, const int );
 
BigInteger operator/( const BigInteger&, const BigInteger& );
BigInteger operator/( const BigInteger&, const long& );
BigInteger operator/( const long&, const BigInteger& );
BigInteger operator%( const BigInteger&, const BigInteger& );
BigInteger operator%( const BigInteger&, const long& );
BigInteger operator%( const long&, const BigInteger& );
BigInteger longDivide( const BigInteger&, const BigInteger& );
BigInteger longDivide( const BigInteger&, const BigInteger&, BigInteger* );
 
bool operator==( const BigInteger&, const BigInteger& );
bool operator==( const BigInteger&, const long& );
bool operator==( const long&, const BigInteger& );
bool operator!=( const BigInteger&, const BigInteger& );
bool operator!=( const BigInteger&, const long& );
bool operator!=( const long&, const BigInteger& );
bool operator<( const BigInteger&, const BigInteger& );
bool operator<( const BigInteger&, const long& );
bool operator<( const long&, const BigInteger& );
bool operator<=( const BigInteger&, const BigInteger& );
bool operator<=( const BigInteger&, const long& );
bool operator<=( const long&, const BigInteger& );
bool operator>( const BigInteger&, const BigInteger& );
bool operator>( const BigInteger&, const long& );
bool operator>( const long&, const BigInteger& );
bool operator>=( const BigInteger&, const BigInteger& );
bool operator>=( const BigInteger&, const long& );
bool operator>=( const long&, const BigInteger& );
 
BigInteger join( const BigInteger&, const BigInteger& );
bool objectEquals( const BigInteger&, const BigInteger& );
BigInteger abs( const BigInteger& );
 
ostream& operator<<( std::ostream&, const BigInteger& );
 
#endif

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial