Class Parameters in C++

Programming, for all ages and all languages.
Locked
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Class Parameters in C++

Post by osdevkid »

Dear All,

Please anybody give some good definition, syntax and example for "Class paramters" in C++
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Class Parameters in C++

Post by Solar »

Context?

"C++ class parameters" could be anything, from an awkward wording for a template class' parameters to something completely different.
Every good solution is obvious once you've found it.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Class Parameters in C++

Post by Solar »

Ah, come on, berkus.

Cut 'em some slack.

While I understand getting annoyed with "easy" questions like these, venting your anger over them too often drags down the signal / noise ratio just as much as the questions themselves...
Every good solution is obvious once you've found it.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Class Parameters in C++

Post by qw »

Especially when the question comes from Osdevkid, who has shown to be an example to all noobs on the forum.
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Re: Class Parameters in C++

Post by osdevkid »

Dear Solar, Berkus,

I am not able to understand your quotes. Actually when I study about "Class Template Specialization", I read the below code

Code: Select all

#include <iostream>
using namespace std;
template <typename T1, typename T2>
class stream
{
  public:
	void f() {	cout << endl << "stream<typename T1, typename T2>::f()";  }
};

template <typename T1>
class stream<T1, int>
{
  public:
	void f() { cout << endl << "stream<typename T1, int>::f()"; }
};

int main()
{
	stream<char, float> si ;
	stream<double, int> sc ;
	si.f();
	sc.f(); 	
	cout << endl;
	return 0 ;
}
Output:
stream<typename T1, typename T2>::f()
stream<typename T1, int>::f()
From the above code I understood the concept "Class Template Specialization" but the line

Code: Select all

class stream<T1, int>
is confusing me, I think "<T1, int>" is "Class Parameters" am I right ?

And I dont know, how to use these two types "<T1, int>" inside the class definition.
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Re: Class Parameters in C++

Post by osdevkid »

berkus wrote:
osdevkid wrote:From the above code I understood the concept "Class Template Specialization"
Awesome! Can you briefly explain it in your own words?
Sorry, that example is actually "Class Template Partial Specialization".

And what I understood is, partial specialization match a given actual template argument list, if the template arguments of the partial specialization can be deduced from the actual template argument list.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Class Parameters in C++

Post by Solar »

In explaining, don't use only the difficult words, use examples, they're easier to understand.

In asking, don't use only the difficult words, use examples, as you are not 100% sure on the subject you are asking about, so the difficult words you're using might be wrong. Even if they're correct, the people you are asking might doubt that fact given that you are unsure on the subject.

And, not to forget, for most people on this forum, there are two language barriers to cross.

That being said, I still don't have a clear picture of what you're unsure about.

And, to reiterate the things that berkus and Hobbes hinted at, in a more friendly manner:

OS development should be done in a language you are intimately familiar with. For learning a programming language, this is the wrong board. http://www.stackoverflow.com has become the standard target for such generic programming questions.
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Class Parameters in C++

Post by Combuster »

if the template arguments of the partial specialization can be deduced from the actual template argument list.
You're hereby convicted of fraud. Your answer shows up 1:1 in google, which means they can never be your own words.

I'm going to side with berkus here: you're a waste of time, please get out. And let's hope that you don't do this at school because it will get you in a lot of trouble if they find out.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Re: Class Parameters in C++

Post by osdevkid »

Yeh, I understood, when we call this line

Code: Select all

stream<double, int> sc;
the second template definition will be called.

Actually my doubt is in the line (second template definition)

Code: Select all

class stream<T1, int>
is it necessary ? instead we can specify it in the above line like this,

Code: Select all

template <typename T1, int>
but it gives error, so we have to specify the Template partial specialization, when we declare the Template Class.

Actually I have confused lot, because of the below additional C++ syntax rules added for Template partial specialization.

Code: Select all

class stream<T1, int>
Shall we recommend C++ compiler developers to have it in the Template definition itself like below

Code: Select all

template <typename T1, int>
I may be wrong, please correct me, why they are following this syntax to accomplish Template partial specialization.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Class Parameters in C++

Post by Combuster »

Solar wrote:For learning a programming language, this is the wrong board.
berkus wrote:Heh, I was right about the "can't read" part.
I'm going to ask for a thread lock now.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Re: Class Parameters in C++

Post by osdevkid »

Dear Combuster,

Thank you for your words, quotes etc., Defnitely you are a genious, no doubt.

You blame me, shame me, etc,. why don't you try to give more info on my question for my understanding.

More students (like me) are coming to this forum, to learn and clarify their doubts, if they see your answers like above, they will defnitely hesistate to post their basic doubts.

I Hope you understand. Thank you once again.
User avatar
osdevkid
Member
Member
Posts: 72
Joined: Sun Nov 21, 2010 11:15 am
Location: India, Chennai

Re: Class Parameters in C++

Post by osdevkid »

Dear Berkus,

I am in right forum.
General Programming
Programming, for all ages and all languages.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Class Parameters in C++

Post by Combuster »

forum rules wrote:3: Please try to meet the intellectual requirements
The point of rules is that you have to follow all of them, not just one of your choice.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Class Parameters in C++

Post by Solar »

When you try being a nitpick, expect to be nitpicked.

At the very top of the page it reads:
OSDev.org
The Place to Start for Operating System Developers
In the Forum Rules it reads:
3: Please try to meet the intellectual requirements
We are not here to babysit new programmers. Operating system development requires academic thinking and a large amount of knowledge. If you don't have the required knowledge then you may learn faster elsewhere.
The linked Wiki article "Getting Started - Required Knowledge" reads:
Programming experience: Learning about programming with an OS project is considered a bad idea. Not only should you know the language in which you will be developing inside out, you should also be familiar with version control, debugging, etc. - in short, you should have written quite a few user-space programs in that language successfully before trying OS development.
Please note that pointing you to http://www.stackoverflow.com is an attempt to be helpful. You will meet a much more generous community there, as far as beginner programmer's questions are concerned.
Every good solution is obvious once you've found it.
Locked