473,396 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Accessing a typedef type that was defined within a template class

Hello guys,

I can't seem to be able to get accsess to a type i declared within a
template class i.e.

template <typename T>
class Array {
public:
typedef std::size_t size_type;

....
....
size_type size() const;

....
private:
....
};

Now i want to implement the size method outside on the class so:
template <typename T>
size_type Array<T>::size() const { ... }

now i know that i can't just use "size_type" but using something like
Array<T>::size_type or Array::size_type can't seem to work either,
however writing T works just fine.

My question is how can i use my typedef size_type outside of the class
declaration?

Any help would be much appreciated, Alex
Aug 30 '08 #1
2 3051
On Aug 30, 12:37*pm, Alex Snast <asn...@gmail.comwrote:
template <typename T>
class Array {
public:
* * *typedef std::size_t * * * *size_type;

...
...
* * size_type size() const;
[...]
Now i want to implement the size method outside on the class so:
template <typename T>
size_type Array<T>::size() const * * *{ ... }
'typename' before the return type:

template <typename T>
typename Array<T>::size_type Array<T>::size() const
{
return 0;
}

Ali
Aug 30 '08 #2
On Aug 30, 10:32*pm, acehr...@gmail.com wrote:
On Aug 30, 12:37*pm, Alex Snast <asn...@gmail.comwrote:
template <typename T>
class Array {
public:
* * *typedef std::size_t * * * *size_type;
...
...
* * size_type size() const;

[...]
Now i want to implement the size method outside on the class so:
template <typename T>
size_type Array<T>::size() const * * *{ ... }

'typename' before the return type:

template <typename T>
typename Array<T>::size_type Array<T>::size() const
{
* * return 0;

}

Ali
Thanks Ali, works now.
Aug 30 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roger Leigh | last post by:
Although I've got over most of my template-related problems, I'm having trouble when I started to use default template parameters. For template type T, I've typedef'd this as object_type and then...
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
4
by: Sacha | last post by:
I'm aware, that up to date, "typedef templates" are not defined within the C++ standard. The seemingly common workaround is this: template <class T> struct MyTypeDef { /* ultimately I need...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
12
by: aaragon | last post by:
Hello all. I have a simple question that seems trivial but I can't make it to work. I have a class that takes as a template argument, another class. The idea is as follows: #include...
3
by: aaragon | last post by:
Hello everyone, I'm trying to run some simple code but for some reason it doesn't work and I've been staring at it for a long time without a single clue of what's going on. This is what happens,...
5
by: Ken Camann | last post by:
I was a bit surprised to find that my compiler (MSVC++) actually accepts the following as legal. It cleans up the code very nicely, but I am sort of confused about some of the finer points of how...
5
by: Lucas Kanebley Tavares | last post by:
Ok, I found a lot of similar errors to this on the net (and here), but none just like it. What I have is a bunch of classes that define a few members, for isntance: class ds_node {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.