Reputation: 3135
I have a simple class definition in Foo.h
like :
template <typename T>
class Foo
{
public:
Foo();
private:
char *topPtr;
}
I've implemented Foo.cpp like :
template <typename T>
Foo<T>::Foo(){
cout<<"default constructor is runned"<<endl;
this.topPtr=NULL;
if(topPtr==NULL){cout<<"topPtr is null"<<endl;}
}
Now, to see whether my Stack constructor is run or not, I write a simple main.cpp like :
#include <iostream>
#include "Foo.h"
using namespace std;
int main(){
Foo<int> foo1();
return 0;
}
I supposed to see "default constructor is runned" and "topPtr is null" messages on my terminal,however I've got nothing. Is there anyone to help me ? Thanks in advance.
Upvotes: 0
Views: 48
Reputation: 56479
You don't need ()
, by using it, you're declaring a function named foo1
that returns Foo<int>
and takes no parameter.
Foo<int> foo1; // It calls default constructor
To use this
pointer you should use ->
not .
this->topPtr // to dereference this pointer
Upvotes: 1