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

No argument constructor and function prototype

bb
Hi,

Class Test {
public:
Test() { cout << "Hello from Test" << endl; }
~Test() { cout << "Bye from Test" << endl; }
};

int main(int argc, char** argv) {

Test t1; // Does call the constructor and i can see the output.
Test t2(); // Compiler (mis)takes it for a function prototype? no
output. why? how to avoid it?

}

Thanks.

Jan 17 '06 #1
2 2728
bb wrote:
Class Test {
public:
Test() { cout << "Hello from Test" << endl; }
~Test() { cout << "Bye from Test" << endl; }
};

int main(int argc, char** argv) {

Test t1; // Does call the constructor and i can see the output.
Test t2(); // Compiler (mis)takes it for a function prototype? no
output. why? how to avoid it?
It's not a mistake. It's a function declaration. Why? Because such is
the rule. Of the language. You just stepped in a puddle. No big deal.
Remember where it is and don't step into it again.

}

Thanks.


V
Jan 17 '06 #2

"bb" <mu**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

Class Test {
public:
Test() { cout << "Hello from Test" << endl; }
~Test() { cout << "Bye from Test" << endl; }
};

int main(int argc, char** argv) {

Test t1; // Does call the constructor and i can see the output.
Test t2(); // Compiler (mis)takes it for a function prototype?
No mistake. It *is* a function prototype. It declares
a function named 't2' which returns a type 'Test' value
and has no parameters. The rule is "if it looks like a
prototype, it is a prototype."
no
output. why?
Prototypes do not generate output.
how to avoid it?


Don't write a prototype if you mean something else.

-Mike
Jan 18 '06 #3

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

Similar topics

4
by: Joerg Toellner | last post by:
Hi Group, sorry, its again me with a dumb question. If i have a function with the optional parameter "mode" like this: void myfunc(char *blah, int mode = NULL) { if(mode == NULL)...
9
by: Matt Eberts | last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object instantiated via a constructor using the arguments object and have it expanded, so to speak, so that it doesn't appear as...
2
by: News | last post by:
Hi, Should the following code compile without errors? class test { public: void display(const int x); };
21
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
13
by: Roy Hills | last post by:
I've seen two different function prototype formats used for ANSI C, and I'm unsure as to which is the correct or preferred one. 1st Format (this is what I use) type function(type, type, type);...
3
by: cybernerdsx2 | last post by:
Hi, I notice a function prototype being declared as following: FileStream.h ========= extern void openFile(char *__ident, int __option); But, in the function declaration part shown as...
2
by: vlsidesign | last post by:
Here is my a portion of my program: #include <stdio.h> main() { int fahr, celsius; int lower, upper, step; int fc_conv(int fahr); ... snip ... }
29
by: Ravishankar S | last post by:
Dear C Experts, While prepating a content for a C course,I made section on function prototypes. Could you kindly provide me your comments on its correctness. Thank you ! Q12: What is the...
7
by: Sheldon | last post by:
Hi, This is a simple mistake so Iam sure there is someone who can help with it: The the file.h: #define IBFLEN 50000 int IRET, ILEN, IUNIT1, IUNIT2, ILOOP, KERR;
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
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: 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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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...

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.