473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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::function()
{
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 7119
"Abhi" <ab*******@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
class className
{
public:
void function();

private:
ofstream constRad;
}

void className::function()
{
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::className()
:
constRad("filename.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("filename.txt") in a "if" condition such as

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

private:
.....
}

int main()
{
className obj(true);
className obj2(false);
}
className::className(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..Ofcourse 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*******@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.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("filename.txt") in a "if" condition such as

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

private:
....
}
[...]
className::className(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::className()
:
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::className(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::className(FileUseDecision 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.txt");
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.txt");


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

Like so:

file.open( "example.txt" );

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
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...
6
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...
1
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:...
8
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...
33
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...
3
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...
1
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...
1
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,...
1
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.