473,785 Members | 3,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error compiling this code

Hi

I have been trying to find out the reason for this error for an 1hr,
please look at it for me.

thanks

*************** * error *************** *
$ make; ./proj
g++ -gdwarf-2 -c -o gen_data.o gen_data.cpp
gen_data.cpp: In member function 'void gen_data::gen_m ngr()':
gen_data.cpp:31 : error: expected primary-expression before ')' token
gen_data.cpp:32 : error: expected primary-expression before '->' token
gen_data.cpp:32 : error: expected primary-expression before '->' token
gen_data.cpp: At global scope:
gen_data.cpp:40 : error: default argument given for parameter 2 of 'void gen_data::once_ gen(std::string , double)'
gen_data.h:17: error: after previous specification in 'void gen_data::once_ gen(std::string , double)'
make: *** [gen_data.o] Error 1

*************** * gen_data.h *************** *
#ifndef GEN_DATA_H
#define GEN_DATA_H
#include <string>
using std::string;

#include <map>
using std::map;

class gen_data
{
const map<string,doub lecur_pairs;
string parent_dir;
void gen_mngr();
void once_gen(string , double val=99);

public:
gen_data(const map<string,doub le>&);
~gen_data();
};

#endif
*************** * gen_data.cpp *************** *
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;

#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
#include "boost/filesystem/fstream.hpp" // ditto
#include "gen_data.h "
namespace fs = boost::filesyst em;

gen_data::~gen_ data(){}

gen_data::gen_d ata(const map<string,doub le& m)
:parent_dir("../data"), cur_pairs(m)
{
gen_mngr();
}

void gen_data::gen_m ngr(){
fs::path data_dir(parent _dir);
if (!exists(data_d ir))//needs an excption handler
cout << parent_dir << " does not exist" << endl;

if (cur_pairs.size ()==0){
fs::directory_i terator end_iter;
for(fs::directo ry_iterator dir_itr(parent_ dir); dir_itr != end_iter; ++dir_itr )
once_gen(dir_it r->leaf());
} else {
typedef map<string,doub le>::const_iter ator mi;
for (mi p = cur_pairs.begin (); p != cur_pairs.end() ; ++mi)
once_gen(mi->first, mi->second);
}
}

void gen_data::once_ gen(string cur_p, double val=99){
cout << cur_p << endl;
}
*************** * main.cpp *************** *
#include <string>
using std::string;

#include <map>
using std::map;

#include "gen_data.h "

int main(){
map <string,doublem ;
m["mothers"]=3;

gen_data gen_job(m);

}

Aug 6 '06 #1
4 2116

"Gary Wessle" <ph****@yahoo.c omskrev i meddelandet
news:87******** ****@localhost. localdomain...
Hi

I have been trying to find out the reason for this error for an 1hr,
please look at it for me.

thanks

*************** * error *************** *
$ make; ./proj
g++ -gdwarf-2 -c -o gen_data.o gen_data.cpp
gen_data.cpp: In member function 'void gen_data::gen_m ngr()':
gen_data.cpp:31 : error: expected primary-expression before ')' token
gen_data.cpp:32 : error: expected primary-expression before '->'
token
gen_data.cpp:32 : error: expected primary-expression before '->'
token
gen_data.cpp: At global scope:
gen_data.cpp:40 : error: default argument given for parameter 2 of
'void gen_data::once_ gen(std::string , double)'
gen_data.h:17: error: after previous specification in 'void
gen_data::once_ gen(std::string , double)'
make: *** [gen_data.o] Error 1

*************** * gen_data.h *************** *
#ifndef GEN_DATA_H
#define GEN_DATA_H
#include <string>
using std::string;

#include <map>
using std::map;

class gen_data
{
const map<string,doub lecur_pairs;
string parent_dir;
void gen_mngr();
void once_gen(string , double val=99);

public:
gen_data(const map<string,doub le>&);
~gen_data();
};

#endif
*************** * gen_data.cpp *************** *
[]
void gen_data::once_ gen(string cur_p, double val=99){
cout << cur_p << endl;
}
For some reason, we are not allowed to repeat the default argument in
the definition of the function. I have never understood exactly why,
but that is the rule.

Just make it "double val /*=99*/" here, and it will work. The default
value will be taken from the function declaration.

Bo Persson
Aug 6 '06 #2
Gary Wessle wrote:
>
if (cur_pairs.size ()==0){
This by the way isn't very efficient if the map has entries.
Try cur_pairs.empty ()
fs::directory_i terator end_iter;
for(fs::directo ry_iterator dir_itr(parent_ dir); dir_itr != end_iter; ++dir_itr )
Try using
dir_itr(data_di r).
The implicit conversion from string to path here may be messing
up...this is the root of the next three errorrs.
>
void gen_data::once_ gen(string cur_p, double val=99){
Default args can only be declared once (you've got it in the header).
Aug 6 '06 #3
Ron Natalie <ro*@spamcop.ne twrites:
Gary Wessle wrote:
if (cur_pairs.size ()==0){

This by the way isn't very efficient if the map has entries.
Try cur_pairs.empty ()
fs::directory_i terator end_iter;
for(fs::directo ry_iterator dir_itr(parent_ dir); dir_itr != end_iter; ++dir_itr )

Try using
dir_itr(data_di r).
The implicit conversion from string to path here may be messing
up...this is the root of the next three errorrs.
void gen_data::once_ gen(string cur_p, double val=99){

Default args can only be declared once (you've got it in the header).
thanks for the suggestions, I have implemented them but the errors are
still there, the suggestions were related to lines in the code
different from the lines whose numbers are in the errors, lines 31,32
are those here

for (mi p = cur_pairs.begin (); p != cur_pairs.end() ; ++mi)
once_gen(mi->first, mi->second);

which look fairly clean to me.

1 #include <string>
2 using std::string;
3 #include <iostream>
4 using std::cout;
5 using std::endl;
6
7 #include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
8 #include "boost/filesystem/fstream.hpp" // ditto
9 #include "gen_data.h "
10 namespace fs = boost::filesyst em;
11
12 gen_data::~gen_ data(){}
13
14 gen_data::gen_d ata(const map<string,doub le& m)
15 :parent_dir("../data"), cur_pairs(m)
16 {
17 gen_mngr();
18 }
19
20 void gen_data::gen_m ngr(){
21 fs::path data_dir(parent _dir);
22 if (!exists(data_d ir))//needs an excption handler
23 cout << parent_dir << " does not exist" << endl;
24
25 if (cur_pairs.empt y()){
26 fs::directory_i terator end_iter;
27 for(fs::directo ry_iterator dir_itr(data_di r); dir_itr != end_iter; ++dir_itr )
28 once_gen(dir_it r->leaf());
29 } else {
30 typedef map<string,doub le>::const_iter ator mi;
31 for (mi p = cur_pairs.begin (); p != cur_pairs.end() ; ++mi)
32 once_gen(mi->first, mi->second);
33 }
34
35 }
Aug 6 '06 #4
Gary Wessle <ph****@yahoo.c omwrites:
Ron Natalie <ro*@spamcop.ne twrites:
>Gary Wessle wrote:
if (cur_pairs.size ()==0){

This by the way isn't very efficient if the map has entries.
Try cur_pairs.empty ()
fs::directory_i terator end_iter;
for(fs::directo ry_iterator dir_itr(parent_ dir); dir_itr != end_iter; ++dir_itr )

Try using
dir_itr(data_di r).
The implicit conversion from string to path here may be messing
up...this is the root of the next three errorrs.
void gen_data::once_ gen(string cur_p, double val=99){

Default args can only be declared once (you've got it in the header).

thanks for the suggestions, I have implemented them but the errors are
still there, the suggestions were related to lines in the code
different from the lines whose numbers are in the errors, lines 31,32
are those here

for (mi p = cur_pairs.begin (); p != cur_pairs.end() ; ++mi)
once_gen(mi->first, mi->second);

which look fairly clean to me.

1 #include <string>
2 using std::string;
3 #include <iostream>
4 using std::cout;
5 using std::endl;
6
7 #include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
8 #include "boost/filesystem/fstream.hpp" // ditto
9 #include "gen_data.h "
10 namespace fs = boost::filesyst em;
11
12 gen_data::~gen_ data(){}
13
14 gen_data::gen_d ata(const map<string,doub le& m)
15 :parent_dir("../data"), cur_pairs(m)
16 {
17 gen_mngr();
18 }
19
20 void gen_data::gen_m ngr(){
21 fs::path data_dir(parent _dir);
22 if (!exists(data_d ir))//needs an excption handler
23 cout << parent_dir << " does not exist" << endl;
24
25 if (cur_pairs.empt y()){
26 fs::directory_i terator end_iter;
27 for(fs::directo ry_iterator dir_itr(data_di r); dir_itr != end_iter; ++dir_itr )
28 once_gen(dir_it r->leaf());
29 } else {
30 typedef map<string,doub le>::const_iter ator mi;
31 for (mi p = cur_pairs.begin (); p != cur_pairs.end() ; ++mi)
32 once_gen(mi->first, mi->second);
33 }
34
35 }
the fix, "I feel stupid"

31 for (mi p = cur_pairs.begin (); p != cur_pairs.end() ; ++p)
32 once_gen(p->first, p->second);
Aug 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2780
by: geek04 | last post by:
i'm using pro*c to precompile my c++ code which accesses oracle 9i database, i'm running a oracle 9i client on my system on compiling the c++ file (generated by pro*c)i'm getting following errors: E:\CODE\VariableRating.cpp(712) : error C2146: syntax error : missing ';' before identifier 'SQL' E:\CODE\VariableRating.cpp(712) : error C2501: 'EXEC' : missing storage-class or type specifiers
6
2734
by: bmwrob | last post by:
I’m very new in C++ programming and am trying to make a decoder tool just for the purpose of learning. I started my project in VC++ 6.0, but after a change of PC, I continued my programming in VS .NET. Now I get a lot of compiling error which I don’t understand. Here is an extract from the code: int iOct; CString sASCII;
8
7837
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED. For this, I used the reference artiicle "http://msdn.microsoft.com/library/default.asp?url=/library/en-...
0
6611
by: Herman Jones | last post by:
I'm getting the following error when I build a Class Library project: Embedding manifest... Project : error PRJ0002 : Error result 1 returned from 'C:\WINDOWS\system32\cmd.exe'. It happens with every the of C++ project I try to build. Not just Class Libraries, but a plain Windows Form Application as well. I've tried creating new projects with nothing but shell built by the Wizard, but I still get the error.
2
5332
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
2
1981
by: stevenruiz | last post by:
Hi Everyone, The Strings.h has the function Get_Line which is defined and the error is shown below: Strings.h: void get_line( istream & );
1
5325
by: sahilrekhi | last post by:
Hi i am working on a graphical user interface deisgn programme. when i compile the file i i get the following output with the mentioned errors: 1>------ Rebuild All started: Project: guiq, Configuration: Debug Win32 ------ 1>Deleting intermediate and output files for project 'guiq', configuration 'Debug|Win32' 1>Compiling... 1>stdafx.cpp 1>Compiling... 1>Custom Message.cpp 1>guiq.cpp 1>Generating Code...
1
1597
by: drajesh | last post by:
hi all, I had a code which is compiling fine on VC++ 6.0 ..but on compiling same code in VS 2005 i m facing following error. error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'CtiCallHandle' (or there is no acceptable conversion) c:\documents and settings\administrator\desktop\rajesh\osi_view\projects\ciscotsp\projects\ciscotsp\SelsiusTSPCall.h 134 static bool IsCtiCallHandleValid(CtiCallHandle...
1
4602
by: SQACPP | last post by:
I have an error when compiling a simple form project... I just start a new Form project and add a new PictureBox in a form(or anything that generate the .resx file) After that when compiling I always get the following error (in VS 2005): Compiling...
6
3634
by: JR | last post by:
The code below compiles and runs perfectly in Windows XP Pro, Using MS VS 2005. If I compile with g++ (cygwin) using the following command line: g++ -pedantic -Weffc++ -Wall -Wctor-dtor-privacy -Wold-style-cast - Woverloaded-virtual -o kk kk.cpp it displays the following errors: kk.cpp: In function `void Burp(std::ostream&, std::vector<std::vector<T, std::allocator<_CharT, std::allocator<std::vector<T, std::allocator<_CharT &)':
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.