Solved

C++ compiler error

Posted on 2008-10-27
6
757 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:tjgquicken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 22817567
Can you show the code that these errors refer to (not just the line, but also the code around and especially before it)
0
 

Author Comment

by:tjgquicken
ID: 22817845
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

0
 
LVL 5

Expert Comment

by:rendaduiyan
ID: 22818804
please show us "biginteger.h".
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 22819886
>> 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.
0
 

Author Comment

by:tjgquicken
ID: 22822639
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

0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 22822980
Don't define max and min. Either use MAX and MIN instead, or use different names.

As a rule, you should NEVER create defines with lowercase characters. All uppercase will avoid a lot of problems.

As a second rule, you shouldn't place defines in a header file, especially not if that header file is included before system header files, like you did here :

        #include "biginteger.h"
        #include "division.h"

(assuming that division.h has system includes in it)

In fact, since this is C++, it's a good idea NOT to use defines at all. Use inline functions or templated functions instead.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question