473,327 Members | 2,074 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,327 software developers and data experts.

Using a function which returns an object

Hi,

In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:

printf("%s", getName( getObject(params) ) ); // Works fine!
getObject(params).read(); // Gives read undefined error.

read is a function of the class in consideration here.

Any clues? Is this allowed at all in C++?

Thanks,
Prateek

Jun 10 '06 #1
9 1620
* si*************@gmail.com:
In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:

printf("%s", getName( getObject(params) ) ); // Works fine!
getObject(params).read(); // Gives read undefined error.

read is a function of the class in consideration here.

Any clues?
"read" is undefined.

Is this allowed at all in C++?


Yes.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 10 '06 #2
Alf P. Steinbach wrote:
* si*************@gmail.com:
In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:

printf("%s", getName( getObject(params) ) ); // Works fine!
getObject(params).read(); // Gives read undefined error.

read is a function of the class in consideration here.

Any clues?


"read" is undefined.

Is this allowed at all in C++?


Yes.


What Alf wants to say here is that you (the OP) didn't provide enough
information to give a more helpful answer. Post a minimal, but complete
program that shows the problem you observed. (If I only got one Euro for
each time I write that sentence...)

Jun 10 '06 #3
Thanks for the replies. Posting a complete program is difficult but
this one should be able to give an idea.

class Test {
getObject(char * param) {
/* code here */
return some-object;
}

void read() {
printf("Hullow!!");
}
}

main() {
Test ob1;
Test ob2;
/*
* Code Here
*
*/
getObject("hi").read(); // I get an error here
}

Hope I made it clear now.

Thanks,
Prateek
}

Rolf Magnus wrote:
Alf P. Steinbach wrote:
* si*************@gmail.com:
In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:

printf("%s", getName( getObject(params) ) ); // Works fine!
getObject(params).read(); // Gives read undefined error.

read is a function of the class in consideration here.

Any clues?


"read" is undefined.

Is this allowed at all in C++?


Yes.


What Alf wants to say here is that you (the OP) didn't provide enough
information to give a more helpful answer. Post a minimal, but complete
program that shows the problem you observed. (If I only got one Euro for
each time I write that sentence...)


Jun 10 '06 #4
On Sat, 10 Jun 2006 13:14:48 -0700, singhal.prateek wrote:
Thanks for the replies. Posting a complete program is difficult but this
one should be able to give an idea.
It should be complete and _compilable_. This is not:
class Test {
getObject(char * param) {
Returning what type?
/* code here */
return some-object;
some minus object? We can't even see the definitions for "some" and
"object", so who knows what applying operator-() to them will do.
}

void read() {
printf("Hullow!!");
}
}
This certainly isn't compilable. No semicolon at the end of the class.

main() {
Where the return type for this too?
Test ob1;
Test ob2;
/*
* Code Here
*
*/
getObject("hi").read(); // I get an error here
Because your code is broken.
}

Hope I made it clear now.


Very. Post a minimal, complete and compilable code example showing your
problem. (Which I'd guess is that you don't ever declare return types
from functions).
Jun 10 '06 #5
On 2006-06-10 21:33, si*************@gmail.com wrote:
Hi,

In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:
In addition to what Alf, Rolf and Andre asked you to include, the whole
error message might also be of help.
printf("%s", getName( getObject(params) ) ); // Works fine!
getObject(params).read(); // Gives read undefined error.


A quick guess would be that getObject() returns a pointer in which case
'->' should be used instead of '.'.

Erik Wikström
--
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure
out how to use my telephone" -- Bjarne Stroustrup
Jun 10 '06 #6
[snip]

Post a minimal, but complete
program that shows the problem you observed. (If I only got one Euro for
each time I write that sentence...)


The funny thing is that if anybody ever heeded that advice they would almost
certainly find the problem themselves. But they never do.

Cy
Jun 10 '06 #7
On 10 Jun 2006 12:33:02 -0700, si*************@gmail.com wrote:
In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:
Any clues? Is this allowed at all in C++?
Thanks,
Prateek


Disclaimer: I do not give a damn how politically correct my response
is. If you don't like it, move on.

I find it quite disturbing that a person who has most likely taken a
job that would have been filled by someone in the western world now
comes into a newsgroup populated mostly by westerners and lazily asks
them to do his job. Murphy's law says the guy who helps him is an
unemployed programmer who is bored.

The ultimate irony - if not out-right insult, is the American people
are funding their own economic demise. The American government pays
companies (tax-credits) to export our high-tech jobs. So it is NOT an
even playing field. It is NOT capital following cheap labor.

"Don't worry about the west, they will sell us the rope we will hang
them with." - attributed to various despotic communist leaders.
Jun 12 '06 #8

JustBoo wrote:
On 10 Jun 2006 12:33:02 -0700, si*************@gmail.com wrote:
In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:
Any clues? Is this allowed at all in C++?
Thanks,
Prateek
Disclaimer: I do not give a damn how politically correct my response
is. If you don't like it, move on.

I find it quite disturbing that a person who has most likely taken a
job that would have been filled by someone in the western world now
comes into a newsgroup populated mostly by westerners and lazily asks
them to do his job. Murphy's law says the guy who helps him is an
unemployed programmer who is bored.


And your problem with that is, sir, what?

The ultimate irony - if not out-right insult, is the American people
are funding their own economic demise. The American government pays
companies (tax-credits) to export our high-tech jobs. So it is NOT an
even playing field. It is NOT capital following cheap labor.
Why not? Sounds like you need to be reeducated--in a Marxist country.

"Don't worry about the west, they will sell us the rope we will hang
them with." - attributed to various despotic communist leaders.


And they failed.

BTW, I think the problem with the guy's code was he did not have a copy
constructor... when you return an object you must have a copy
constructor I recall from my never used textbook on OOP.

RL

Jun 12 '06 #9

JustBoo wrote:
On 10 Jun 2006 12:33:02 -0700, si*************@gmail.com wrote:
In a class, I have a static function which returns a particular object
of the class depending on the arguments. Now, if I use this function to
call another method of the class, I get an error. It is like:
Any clues? Is this allowed at all in C++?
Thanks,
Prateek


Disclaimer: I do not give a damn how politically correct my response
is. If you don't like it, move on.

I find it quite disturbing that a person who has most likely taken a
job that would have been filled by someone in the western world now
comes into a newsgroup populated mostly by westerners and lazily asks
them to do his job. Murphy's law says the guy who helps him is an
unemployed programmer who is bored.

The ultimate irony - if not out-right insult, is the American people
are funding their own economic demise. The American government pays
companies (tax-credits) to export our high-tech jobs. So it is NOT an
even playing field. It is NOT capital following cheap labor.

"Don't worry about the west, they will sell us the rope we will hang
them with." - attributed to various despotic communist leaders.


har har har har :)

this is one of bests troll posts I've seen ever :-)

Jun 13 '06 #10

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

Similar topics

28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
6
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it...
4
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp(...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
29
by: shuisheng | last post by:
Dear All, The problem of choosing pointer or reference is always confusing me. Would you please give me some suggestion on it. I appreciate your kind help. For example, I'd like to convert a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.