invoke non-static function using ::

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


Confused why the following code can compile when we use :: to invoke non-static function. Especially, in the sample below, is it possible to call non-static member if T is not int? Why compiler allows the following code to compile?

Code:
#include <iostream>

using namespace std;

template  <class T>
struct FooTrait {
public:
	int foo1();
};

template<>
struct FooTrait<int> {

	static int foo1() {cout << "Hello Foo1" << endl; return 0;}
};

template <class T1, class T2 = FooTrait<T1>>
struct Foo {
public:
	int foo()
	{
		T2::foo1(); // possible to call non-static member if T is not int?

		return 0;
	}
};

 int main()
 {
	 Foo<int> f;
	 f.foo();
	 return 0;
 }


thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top