Strange non-error (What DOES it do?)

I have been playing with some code generation and I ran across something that would seem like it should rais a compile error but it doesn't. However, it does not function as one might think either. What does it do? (See a2)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;

class A {
public:  
  A() { cout << "Constructing" << endl;}
 ~A() { cout << "Destructing" << endl;}
};
int main (void) {
  A a1;               // <-- this works, constructs and destructs
  A a2();             // <-- this doesn't construct or destruct

  return 0;
}


Thanks,

-- Abs
A a2(); a function that returns an `A' object and receives no parameters.
I misunderstood what you said and posted incorrectly.

So what I am actually doing is creating a forward declaration, (prototype statement). So it is valid for the compiler, but surely it doesn't do what was expected :)

However, if I had a constructor such as:
1
2
3
class A {...
  A(int junkInteger) { //do something here...}
...}


I could declare:
 
   A anA(3);


In much the same way I could declare and instantiate integers:
 
  int iVal(7);


or strings:
 
  string myString("Hello, World!");


Seems an strange syntactical twist, no?
Topic archived. No new replies allowed.