Initializer Error

Problems with compiling

Page 1 of 1

9 Replies - 23458 Views - Last Post: 12 September 2006 - 05:29 AM Rate Topic: -----

#1 grinsalot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Initializer Error

Posted 09 September 2006 - 07:02 AM

Hi,

Can someone please help me with an error I receive when compiling my program. The error states the following:

g++ -g -c functions.cpp
functions.cpp:14: error: expected initializer before "using"
make: *** [functions.o] Error 1
-bash-3.00$ 


My code is as follows:
#include <iostream>
#include "functions.h"
using namespace std;

int cuckoo(int& running_hours, int& minutes)
{
 for(int i=0;i<running_hours;i++)
{
  for(int minutes=1;minutes<60;minutes++)
{
 if(minutes==15 || minutes==30 || minutes == 45){
   std::cout << minutes <<" --" << " Cuckoo!" << '\n';
   }
}
  }

}
double time(double& running_hours, int& minutes, double& starting_hour)
{
  for(int i=0;i<running_hours;i++)
	for(int j=0;j<=60;j++)
	  if(minutes==60)
		{
		  minutes=minutes-60;
		  starting_hour=starting_hour + 1;
		}
}



Thank you in advance.

This post has been edited by grinsalot: 09 September 2006 - 07:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Initializer Error

#2 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Initializer Error

Posted 09 September 2006 - 07:22 AM

since you delcared:

using namespace std;

I dont thing you need to do the std:: in this line:
std::cout << minutes <<" --" << " Cuckoo!" << '\n';
try it like this:
cout << minutes <<" --" << " Cuckoo!" << '\n';
Was This Post Helpful? 0
  • +
  • -

#3 grinsalot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Re: Initializer Error

Posted 09 September 2006 - 07:27 AM

View PostNova Dragoon, on 9 Sep, 2006 - 07:22 AM, said:

since you delcared:

using namespace std;

I dont thing you need to do the std:: in this line:
std::cout << minutes <<" --" << " Cuckoo!" << '\n';
try it like this:
cout << minutes <<" --" << " Cuckoo!" << '\n';


Hi Nova Dragoon,
Thank you for your post. Unfortunately it didn't work. This is the error I now receive:
functions.cpp:14: error: expected initializer before "using"
functions.cpp: In function `void cuckoo(int&, int&)':
functions.cpp:23: error: `cout' was not declared in this scope
make: *** [functions.o] Error 1
-bash-3.00$ 

Was This Post Helpful? 0
  • +
  • -

#4 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: Initializer Error

Posted 09 September 2006 - 07:47 AM

There may be a syntax error in your functions.h file

check that and if you cant pin it down, post it here and we'll look at it.
Was This Post Helpful? 0
  • +
  • -

#5 grinsalot  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 50
  • Joined: 08-April 06

Re: Initializer Error

Posted 09 September 2006 - 08:25 AM

View PostNova Dragoon, on 9 Sep, 2006 - 07:47 AM, said:

There may be a syntax error in your functions.h file

check that and if you cant pin it down, post it here and we'll look at it.



Thank you, Nova Dragoon. You are correct. I was missing a semicolon
after one of my function declarations. Thank you again!
Was This Post Helpful? 0
  • +
  • -

#6 Antiokus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 192
  • Joined: 06-September 06

Re: Initializer Error

Posted 11 September 2006 - 02:40 PM

About what nova dragoon mentioned about "using namespace std;", the syntax would be "using std::cout;" instead. With that, you can eliminate the std:: before 'cout'.
Was This Post Helpful? 0
  • +
  • -

#7 dorknexus  Icon User is offline

  • or something bad...real bad.
  • member icon

Reputation: 1255
  • View blog
  • Posts: 4,618
  • Joined: 02-May 04

Re: Initializer Error

Posted 11 September 2006 - 04:43 PM

Quote

About what nova dragoon mentioned about "using namespace std;", the syntax would be "using std::cout;" instead. With that, you can eliminate the std:: before 'cout'.


using namespace std; does the same thing as the cout object resides in the 'std' namespace.
Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Initializer Error

Posted 11 September 2006 - 06:14 PM

Very true...using namespace std will import the whole namespace, but eliminates the need to specify each element of the namespace you wish to use.
Was This Post Helpful? 0
  • +
  • -

#9 Xing  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Re: Initializer Error

Posted 11 September 2006 - 09:46 PM

View PostDark_Nexus, on 12 Sep, 2006 - 05:13 AM, said:

using namespace std; does the same thing as the cout object resides in the 'std' namespace.

If you bring the entire namespace in current scope like this, it defeats the whole purpose of namespaces.

This post has been edited by Xing: 11 September 2006 - 09:46 PM

Was This Post Helpful? 0
  • +
  • -

#10 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Initializer Error

Posted 12 September 2006 - 05:29 AM

I would say that depends on how many elements from the namespace you'll be using in your application. If you are using numerous elements from the std namespace, I would think it acceptable to bring it into scope (although also somewhat dependant on how many other namespaces you'll be using).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1