Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ compiler error

Posted on 2008-10-27
6
Medium Priority
?
763 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

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!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

916 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