473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error C2064 : term does not evaluate to a function using 1 arguments

Hi all,

I am using .net for C++ and I would like to write some variable values
to some files.

I will be using that file in many member functions of the class. So I
declared the file variable names in class.

And I declared that to a file name in one member function.

Example:

class className
{
public:
void function();

private:
ofstream constRad;
}

void className::func tion()
{
constRad ("filename.txt" );
}

and in other member functions I used this variable "constRad" to write
some variable values in the textfile.

But am getting an error as

"Error C2064 : term does not evaluate to a function using 1 arguments"

Could you please help me in this.

Thanks
Abbi.

Oct 5 '05 #1
7 7123
"Abhi" <ab*******@yaho o.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
class className
{
public:
void function();

private:
ofstream constRad;
}

void className::func tion()
{
constRad ("filename.txt" );
}


You wrote it as if you were calling a function named constRad. You want to
initialize it in the constructor:

// Note the name of the function; also, no return value
// (this is the constructor)

className::clas sName()
:
constRad("filen ame.txt")
{}

Of course you need to declare the constructor in the class definition:

class className
{
/* ... */
className(); // constructor declaration
};

Ali

Oct 5 '05 #2
Hi Ali,

Thanks for immediate reply.

I even tried that before, keeping it in the constructor.

But what actually I need is that, I would like to write the values to
file only for one of the two objects I have. So I kept the constructor
as shown below.
and only if bool is true,which I initialized for one object, I need to
write the values to the file.. so in the constructor, I wrote

constRad("filen ame.txt") in a "if" condition such as

class className
{
className(bool) //constructor
public:
....

private:
.....
}

int main()
{
className obj(true);
className obj2(false);
}
className::clas sName(bool boolvar)
{
if(boolvar == true)
constRad("..... .txt");
}
and didnt write anything for else part...

and was still getting that error.. how to do it only for one object
(obj).. If I write that in just the constructor without any if
condition, then it will try to overwrite the samefile for different
objects.. though I dont try to write any variable values for the second
object(obj2), I dont know if that would be a problem.

Thanks,
Abbi.

Oct 5 '05 #3
Hi Ali,

Small clarification,

In the above example code I wrote some things which are not similar to
what I did in my code, which you might think are the errors or which
may be the actual errors. that is in class declaration..Of course those
should be there by default, but just wanted to let you know.

class className
{

public:
className(bool) //constructor
....
private:
.....
} ;

Also, I tried putting constRad("..... txt") outside the if condition, to
check if it doesnt give any errors. But still am getting the same
error..

Thanks,
Abbi.

Oct 6 '05 #4
"Abhi" <ab*******@yaho o.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
But what actually I need is that, I would like to write the values to
file only for one of the two objects I have. So I kept the constructor
as shown below.
and only if bool is true,which I initialized for one object, I need to
write the values to the file.. so in the constructor, I wrote

constRad("filen ame.txt") in a "if" condition such as

class className
{
className(bool) //constructor
public:
...

private:
....
}
[...]
className::clas sName(bool boolvar)
{
if(boolvar == true)
constRad("..... .txt");
}


You are still using a syntax that looks like a function call, but you can do
it only in the constructor initialization list as in

className::clas sName()
:
constRad("..... .txt")
{}

The problem with your constructor is that, once you are in the constructor
body, constRad is already default-constructed: it is a proper object that is
not associated with a file yet. You shouldn't use the initialization syntax
in the constructor body anymore.

You can open the file though:

className::clas sName(bool boolvar)
{
if (boolvar) // <-- comparing with 'true' is not needed
{
constRad.open(" ......txt");
}
}

[...]

As an aside, it is better to introduce an enum to make the decision:

enum FileUseDecision { useFile, dontUseFile };

Once you have that, the code will be more clear:

className::clas sName(FileUseDe cision decision)
{
if (decision == useFile)
{
constRad.open(" ......txt");
}
}

Ali

Oct 6 '05 #5
Hi Ali,

I am sending a small code which I wrote to just check this. And am
still getting the same error.

#include <iostream>
#include <fstream>

using namespace std;

class Abhi
{
public :
Abhi();
void filewrite();
private:
ofstream file;
};

Abhi::Abhi()
{
file("example.t xt");
file<<"\n\n This is example\n\n";
}
int main()
{
Abhi a;
a.filewrite();
system("PAUSE") ;
return 0;
}
Could you please send me the correct syntax for this file so that I can
make use of that in my code accordingly as what you said in the
previous message.

Thanks,
Abbi.

Oct 6 '05 #6

Abhi wrote:
ofstream file;
Here you're object is constructed....
file("example.t xt");


.... so at this point, you simply need to open it.

Like so:

file.open( "example.tx t" );

Oct 6 '05 #7
Okay, Problem solved !!!!

Thanks Ali and int2str for the help.. Now am able to do it without any
error...

Thanks once again..
Abbi..

Oct 6 '05 #8

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

Similar topics

1
3233
by: Donald Canton | last post by:
Hi, I'm using Bjarne's book to learn C++ and am stuck on the Calc program in Section 6. Everything works fine except when I try to use istringstream to parse a token from the command line. I thought I followed his instructions on page 118 correctly, but I can't get it to compile without syntax errors in the get_token() function. The whole program follows with the four syntax errors flagged with the text "// SYNTAX ERROR". Thanks in...
6
2170
by: kushalsoftpro | last post by:
Hi I am using STL map in VC++6.0 application. type of project is MFC DLL. My code looks like:-- typedef std::map <unsigned long,LPVOID, BOOL> MyMap; In class definition file i am using this map as:-- MyMap m_mapPHLRecorder ;
1
1690
by: Skavenger | last post by:
Hi, I'm attempting to use a class member function pointer to call a relevant function. This is done like this.... typedef void(SampleA::*SAMPLEAFUNC)(void); class SampleA { public: SampleA() { memFunc = testFunc; } ~SampleB() {};
8
2534
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined in global space, therefore it is not a global variable, yes? Even if it was global, how would it get from one function to another? In PHP variables are copied by value. Are they copied by reference in Javascript? <SCRIPT LANGUAGE="JavaScript">
33
3142
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on that ID, otherwise it returns false. **I am not looking for comments on the usefulness of this function - it is only to demonstrate error handling** There are three versions of this code. David Fenton says under the earlier thread "DAO...
3
5244
blackstormdragon
by: blackstormdragon | last post by:
I keep getting this error when building my code. error C2064: term does not evaluate to a function taking 1 arguments. #include<iostream> #include<cmath> using namespace std; double areaFunction(double,int,int,int); int perimeterFun(int,int,int); void main()
1
1950
by: patilanjana | last post by:
Hi, I am getting above mentioned errors. Checked msdn, read the comments but I fail to implement it. Please help. Error is regarding using the new and delete operators. Although I do write both, the compiler is not matching them and I guess there is a memory leak. Program hangs after main returns, thats weired to me. Thanks for all the help. Really appreciate it.
1
1584
by: prads | last post by:
Hello, I found this waitbar functioning pgm in a forum which does the same work as a matlab waitbar. However this pgm has an error and i cudnot figure it out. Can anyone pls correct it. Thanks, Prads /************************************************************************** * Waitbar function -- displays progress of lengthy calculations * ------------------------------------------------------------- * Copyright (c) 2002 Quentin...
1
1891
by: George2 | last post by:
Hello everyone, Here is the code, and if I change line from static wchar_t* p = {PREFIX((wchar_t*)_TEXT("FOO"))}; to static wchar_t* p = {PREFIX(_TEXT("FOO"))};
0
8413
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
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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,...
1
6176
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
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.