Click here to Skip to main content
15,920,503 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: instantiation point discussion Pin
Rajkumar R7-Mar-08 22:43
Rajkumar R7-Mar-08 22:43 
GeneralRe: instantiation point discussion Pin
George_George7-Mar-08 23:01
George_George7-Mar-08 23:01 
GeneralRe: instantiation point discussion Pin
Rajkumar R7-Mar-08 23:23
Rajkumar R7-Mar-08 23:23 
GeneralRe: instantiation point discussion Pin
George_George8-Mar-08 22:03
George_George8-Mar-08 22:03 
GeneralRe: instantiation point discussion Pin
Rajkumar R9-Mar-08 2:07
Rajkumar R9-Mar-08 2:07 
GeneralRe: instantiation point discussion Pin
George_George9-Mar-08 2:24
George_George9-Mar-08 2:24 
GeneralRe: instantiation point discussion Pin
Rajkumar R9-Mar-08 3:01
Rajkumar R9-Mar-08 3:01 
GeneralRe: instantiation point discussion Pin
George_George9-Mar-08 3:15
George_George9-Mar-08 3:15 
Thanks Rajkumar!


I found after discussion with you these days, most of my confusions are solved. Cool!!

But still one confusion can not be solved, I show my confusion in below code.

I do not know why there is compile error below (compile error posted), and if I remove statement "cout << d.get_i() << endl; // output 200", there will not be any compile errors?

My confusion is, I think whether or not we call get_i, Derived<int> is instantised, right? Instantised means having the same code, why whether we call a member function or not will impact compile result? Is there some new rules we do not cover theses days about instantiation of template class?

Compile errors,

1>------ Build started: Project: test_template4, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(15) : error C2955: 'Base' : use of class template requires template argument list
1>        d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(5) : see declaration of 'Base'
1>        d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(21) : see reference to class template instantiation 'Derived<T>' being compiled
1>d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(15) : error C2955: 'Base' : use of class template requires template argument list
1>        d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(5) : see declaration of 'Base'
1>        d:\visual studio 2008\projects\test_template4\test_template4\main.cpp(26) : see reference to class template instantiation 'Derived<T>' being compiled
1>        with
1>        [
1>            T=int
1>        ]


#include <iostream>

using namespace std;

template <typename T> struct Base {
public:	
	Base (int _i): i (_i)
	{

	}

	int i;
};

template <typename T> struct Derived : public Base/*<T>*/ {
public:
	Derived (int _i) : Base<T> (_i)
	{
	}
	int get_i() { return i; }
};


int main()
{
	Derived<int> d (200);
	cout << d.get_i() << endl; // output 200
	return 0;
}



regards,
George
AnswerRe: instantiation point discussion Pin
Rajkumar R9-Mar-08 3:27
Rajkumar R9-Mar-08 3:27 
GeneralRe: instantiation point discussion Pin
George_George9-Mar-08 15:28
George_George9-Mar-08 15:28 
GeneralMSDN template sample Pin
George_George7-Mar-08 20:36
George_George7-Mar-08 20:36 
GeneralRe: MSDN template sample Pin
CPallini7-Mar-08 23:29
mveCPallini7-Mar-08 23:29 
GeneralRe: MSDN template sample Pin
George_George8-Mar-08 21:59
George_George8-Mar-08 21:59 
GeneralRe: MSDN template sample Pin
CPallini8-Mar-08 22:55
mveCPallini8-Mar-08 22:55 
GeneralRe: MSDN template sample Pin
George_George9-Mar-08 2:05
George_George9-Mar-08 2:05 
GeneralRe: MSDN template sample Pin
CPallini9-Mar-08 3:57
mveCPallini9-Mar-08 3:57 
GeneralRe: MSDN template sample Pin
George_George9-Mar-08 15:22
George_George9-Mar-08 15:22 
GeneralRe: MSDN template sample Pin
CPallini9-Mar-08 22:08
mveCPallini9-Mar-08 22:08 
GeneralRe: MSDN template sample Pin
George_George9-Mar-08 22:35
George_George9-Mar-08 22:35 
QuestionRe: MSDN template sample Pin
CPallini9-Mar-08 22:48
mveCPallini9-Mar-08 22:48 
GeneralRe: MSDN template sample Pin
George_George9-Mar-08 23:41
George_George9-Mar-08 23:41 
Questionneed a very simple compiler written in visual c++!!! Pin
faradgi7-Mar-08 20:18
faradgi7-Mar-08 20:18 
AnswerRe: need a very simple compiler written in visual c++!!! Pin
Rajesh R Subramanian7-Mar-08 20:31
professionalRajesh R Subramanian7-Mar-08 20:31 
GeneralRe: need a very simple compiler written in visual c++!!! Pin
CPallini7-Mar-08 23:24
mveCPallini7-Mar-08 23:24 
GeneralRe: need a very simple compiler written in visual c++!!! Pin
Hamid_RT9-Mar-08 0:51
Hamid_RT9-Mar-08 0:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.