Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using value_type=T;

33 views
Skip to first unread message

Doug Mika

unread,
May 28, 2015, 4:46:10 PM5/28/15
to
I have this neat little self defined Vector class (not quite complete, but merely useful to illustrate a purpose of using value_type=T), and my question is, in this class definition is value_type a member like size? Does a unique value_type exist for each instance of Vector? Or is it like a static member?

#include <iostream>

using namespace std;

template<typename T>
class Vector{
public:
using value_type=T;
Vector(int s){
this->size = s;

}
private:
int size;
T element;
};

int main()
{
//Testing the functionality
Vector<char> v(1);
Vector<char>::value_type a='u';
decltype(v)::value_type b='v';
cout<<a<<" "<<b<<endl;
}

red floyd

unread,
May 28, 2015, 4:56:36 PM5/28/15
to
Neither. It's more like a typedef.

Consider:

struct A {
struct B {
int x;
};
int y;
};

Same thing. Is "struct B" a member like y? No.
Does a unique "struct B" exist for each instance of A? No.

To paraphrase Pauli, the question isn't right... it isn't even wrong.

Doug Mika

unread,
May 28, 2015, 5:03:25 PM5/28/15
to
But we can refer to it using the scope resolution operator?

Victor Bazarov

unread,
May 28, 2015, 5:08:27 PM5/28/15
to
Yes, we can. A class is a namespace. Anything you declare in it can be
referred to using a scope resolution operator. Whether it makes sense
to do so depends on the context.

A class defined in a class is similar to a class defined in a namespace,
except that the class has access specifiers, and a namespace does not.
It's a member that can be public, private, or protected.

V
--
I do not respond to top-posted replies, please don't ask
0 new messages