Is there an elegant/efficient way to use a typedef of a class passed in
to a template parameter. I know that a second template parameter can
be given, but I was wondering if there is any way to avoid that.
Thanks,
ThazKool
[code]
template< class T >
class BTree
{
public:
void Query( T::Type value );
void Update( T::Type value, T::Type update );
void Delete( T::Type value );
void Insert( T node );
unsigned int Count() { return _count; };
private:
unsigned int _count;
}; 7 2698
ThazKool wrote: Is there an elegant/efficient way to use a typedef of a class passed in to a template parameter. I know that a second template parameter can be given, but I was wondering if there is any way to avoid that.
Thanks, ThazKool
[code] template< class T > class BTree { public: void Query( T::Type value ); void Update( T::Type value, T::Type update ); void Delete( T::Type value ); void Insert( T node ); unsigned int Count() { return _count; };
private: unsigned int _count; };
I don't understand what your attempting to do.
What is T::Type? If 'T' is of class 'Apple',
then 'Insert( T node )' would become
'Insert( Apple node )'. What do you want
'Query( T::Type value)' to be when 'T' is an
'Apple'?
Are you aware that std::set, std::multiset, std::map,
and std::multimap are (usually) backed by a red-black
tree? You could use those, instead of implementing
your own B-Tree.
Regards,
Larry
--
Anti-spam address, change each 'X' to '.' to reply directly.
> Is there an elegant/efficient way to use a typedef of a class passed
in to a template parameter. I know that a second template parameter can be given, but I was wondering if there is any way to avoid that.
What do you mean? Doing something for T::Type? A simple
typedef typename T::Type Type;
will do.
Thanks, ThazKool
[code] template< class T > class BTree { public: void Query( T::Type value ); void Update( T::Type value, T::Type update ); void Delete( T::Type value );
These are all illegal. Since Type is a type depending on a template
parameter, you must use 'typename':
void Query(typename T::Type value);
Your compiler may not be up to date.
Jonathan
ThazKool wrote: Is there an elegant/efficient way to use a typedef of a class passed in to a template parameter. I know that a second template parameter can be given, but I was wondering if there is any way to avoid that.
Thanks, ThazKool
[code] template< class T > class BTree { public: void Query( T::Type value ); void Update( T::Type value, T::Type update ); void Delete( T::Type value ); void Insert( T node ); unsigned int Count() { return _count; };
private: unsigned int _count; };
Try:
template< class T >
class BTree
{
public:
void Query( typename T::Type value );
void Update( typename T::Type value, typename T::Type update );
void Delete( typename T::Type value );
void Insert( T node );
unsigned int Count() { return _count; };
private:
unsigned int _count;
};
Best
Kai-Uwe Bux
BTW: before implementing your own container type, you might think
about using the standard containers (unless you are doing this
just for fun, that is).
Larry I Smith wrote: Are you aware that std::set, std::multiset, std::map, and std::multimap are (usually) backed by a red-black tree? You could use those, instead of implementing your own B-Tree.
A B-Tree is not necessarily a binary tree. Actually, in most
cases it isn't, because B-Trees ought to expand in breadth, not in
height (binary trees would grow too high to implement an efficient data
lookup in a database for example).
A red-black tree is always a binary tree however.
--
Matthias Kaeppler
Thank you all. I am researching the typename keyword works well. I
should have posted all of the code. It is listed below. It seems as
though my Btree is not really a Btree. Anyway, I am doing this for
some fun learning.
Thanks,
ThazKool
template< class T >
class BTree
{
public:
void Query( typename T::Type value );
void Update( typename T::Type value, typename T::Type update );
void Delete( typename T::Type value );
void Insert( T node );
unsigned int Count() { return _count; };
private:
unsigned int _count;
};
template< typename T >
class BTreeNode
{
public:
//BTreeNode( value, left, middle, right );
typedef T Type;
private:
BTreeNode<T>* _left;
BTreeNode<T>* _middle;
BTreeNode<T>* _right;
T _value;
};
I am interested in learning more about data structures for efficient
data lookup for databases. Do you know any good informative links on
the subject?
Thanks,
ThazKool
ThazKool wrote: I am interested in learning more about data structures for efficient data lookup for databases. Do you know any good informative links on the subject?
Thanks, ThazKool
Hm, not really, sorry. But you can read about B and B+ trees in about
every book on database systems, they're pretty common.
--
Matthias Kaeppler This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Andrew Ward |
last post by:
Hi All,
Considering the following code:
struct A;
struct B
{
std::list<A> l;
};
|
by: Gianni Mariani |
last post by:
I remember seeing a neat template specialization trick posted here a few
months ago that allowed the detection of a type containing a member.
After a day searching through google archives I come up zip.
Anyhow, after much trial and error I came up with this. This
"contains_member" template sets value to 1 if the type D contains
a typedef named MEMBER of type TD.
|
by: David Komanek |
last post by:
Hi all,
I am trying to learn more about how to use g++/Cygwin to produce dll
files on WinXP. And I have a problem which at the first look seems to
be an obvious dll-export problem, but I don't think this is really the
issue. Here is a description of my problem.
MathLibrary.dll:
- SpaceTimeVector (uses various stuff from this dll)
|
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 y = x;
but I can't understand the last one which is
Array<int>::element_type y = x;
We have a typedef T element_type; in the template Array class see below
|
by: Ondrej Spanel |
last post by:
The code below does not compile with .NET 2003, I get folowing error:
w:\c\Pokusy\delegTemplArg\delegTemplArg.cpp(11) : error C2993: 'float' :
illegal type for non-type template parameter 'x'
The error shows compiler is quite confused - x is not a template parameter
at all.
I have found two workarounds, but still I think the code should compile.
| |
by: Kai-Uwe Bux |
last post by:
Hi folks,
I would like to know which clause of the standard rules out this:
template < typename eval >
struct recursive_template {
typedef typename eval::enum_type Enum;
|
by: danilo.horta |
last post by:
Hi guys
I'm trying to accomplish a slightly difficult task. I think it's more
easy to explain trought an unworking code:
template<class T, size_t numDim> VecBasis {/*...*/};
typedef VecBasis<float, 3> vec3;
template<class T, size_t size> class MatBasis {
//...
|
by: Raider |
last post by:
I'm trying to create a base class who will contain generic algoritms
and derived class(es) who will perform problem-specific things. I'm
unable to use dynamic polymorphism, because base class know nothing
about problem-specific types. I wrote the following code using static
polymorphism, but compiler do not allow me to use type traits as a
template parameter, the following code not compiles:
template <class CT>
struct InfoClass
{
|
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 <iostream>
using namespace std;
template <class ClassB>
class ClassA
|
by: Gaijinco |
last post by:
I'm trying to do a template class Node.
My node.hpp is:
#ifndef _NODE_HPP_
#define _NODE_HPP_
namespace com { namespace mnya { namespace carlos {
template <typename T>
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |