0

I have a class

class Test{
public:
    Test(){};
    ~Test(){};
    void test() {cout<<"test"<<endl;};
};

and in main.cpp I have:

#include "Test.h"

using namespace std;

int main(){
     Test t();
     t.test();
}

Is this right way to declare method or am I getting it wrong? VS2010 doesn't recognise this method at all. It states that

expression must have a class type

aschepler
  • 70,891
  • 9
  • 107
  • 161
miller
  • 1,636
  • 3
  • 26
  • 55

2 Answers2

2

You are declaring a function here:

Test t(); // function t(), returning a Test instance

Try this instead:

Test t;  // t is a Test instance
Test t2{}; // t2 is a Test instance, C++11 only
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
0
First thing is that 
class Test{
public:
    Test(){};(Your Default Constructor when you will make the object this constructor will call)
    ~Test(){};(when you will release this object your destructor will call)
    void test() {cout<<"test"<<endl;};
};
Here you don't need to call manually.
9827085704
  • 29
  • 2