473,769 Members | 4,303 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

debug message in a template class

template <class T>
class BufferQueue{
public:
int BufferQueue<T>: :pushToQueue(T pkt, int timeout);
}

template<class T>
int BufferQueue<T>: :pushToQueue(T pkt, ACE_Time_Value *timeout){
cout<<"in pushToQueue"<<e ndl; --------Line p
return 0;
}

Suppose I have two instances BufferQueue<A_a , BufferQueue<B_b ;
I want to know which instance I'm in by printing some debug messages
out in Line p
like
"in pushToQueue of A", etc.

How can I tell the compiler or change Line p to make it?
Sep 30 '08 #1
4 1410
On Sep 30, 2:46*pm, thomas <FreshTho...@gm ail.comwrote:
template <class T>
class BufferQueue{
public:
* * * * * int BufferQueue<T>: :pushToQueue(T pkt, int timeout);

}

template<class T>
int BufferQueue<T>: :pushToQueue(T pkt, ACE_Time_Value *timeout){
* * * * * cout<<"in pushToQueue"<<e ndl; * * * * * ** --------Line p
* * * * * return 0;

}

Suppose I have two instances BufferQueue<A_a , BufferQueue<B_b ;
I want to know which instance I'm in by printing some debug messages
out in Line p
like
"in pushToQueue of A", etc.

How can I tell the compiler or change Line p to make it?
You can define a static memeber function like T::GetName() which
returns
the name of the class, so

cout << "in pushToQueue " << T::GetName() << endl;

Or you may have typeid(T).name( ) output as message.
Sep 30 '08 #2
>
You can define a static memeber function like T::GetName() which
returns
the name of the class, so

cout << "in pushToQueue " << T::GetName() << endl;
How can you write the "GetName" method?
>
Or you may have typeid(T).name( ) output as message.- Hide quoted text -

- Show quoted text -
Yeah.. The typeid function should work. Thanks.
Sep 30 '08 #3
On Sep 30, 11:18 am, thomas <FreshTho...@gm ail.comwrote:

[...]
Or you may have typeid(T).name( ) output as message.- Hide
quoted text -
Yeah.. The typeid function should work. Thanks.
It should, but whether it does or not is a quality of
implementation issue. As far as the standard is concerned, an
implementation which always returns "" is fully conforming. In
practice, most implementations (with the notable exception of
g++) do return something useful.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 30 '08 #4
On Sep 30, 5:18*pm, thomas <FreshTho...@gm ail.comwrote:
You can define a static memeber function like T::GetName() which
returns
the name of the class, so
cout << "in pushToQueue " << T::GetName() << endl;

How can you write the "GetName" method?
template <class T>
struct MyClass
{
void MyFunc() const
{
std::cout << T::GetName() << std::endl;
}
};

Here every instatiation of T is requred
to have a static function named "GetName";

struct T_type1
{
static char const* GetName() { return "T_type1"; }
};

int main()
{
MyClass<T_type1 c1;
c1.MyFunc();
}

>
Or you may have typeid(T).name( ) output as message.- Hide quoted text -
- Show quoted text -

Yeah.. The typeid function should work. Thanks.
Sep 30 '08 #5

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

Similar topics

1
3343
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me to turn a previously made String class that deals with char's into a templated String class that uses the template parameter C instead of char. I thought it would be fairly simple to do this exercise, but I encoutered many errors for my...
1
1202
by: rolo | last post by:
Im trying to do a recursive algoritm and debug it. My problem is that I got segfault if I run it withous optimizing it with the compiler, since I want to debug it. If I use a smaller number it runs ok, but im interested on bigger numbers. Can anyone help me out and explain why this happens? heres a sample code: (it doesn't matter if I use template or not, I got the same results) If I optimize it with -O3 or -O2 the program runs fine...
9
1717
by: Nick Forrington | last post by:
Hi, I'm making a program and have a static Console class that I'm using to output things, these get sent to the console and also to the graphics on screen (I'm using SDL). One thing I'm having a bit of trouble with is passing strings and numbers in the same arguement e.g. Console::println("X=" + x); kind of thing?
4
1692
by: marcus | last post by:
I have this class A that contains a method A_method that opens a file and does fgets. I also have a template class B that contains a method B_method that takes a class A object as template type. B_method then uses this A object to call A_method. here is a snippet (pseudo) In class A.cpp:
1
1805
by: marco_segurini | last post by:
Hi, At the moment I am using Visual Studio 2005 beta 1. The following program does not compile using the debug configuration setting the "Disable Language Extensions" flag to "Yes(/Za)" while using the release configuration the build has no problem. Setting "Disable Language Extensions" flag to "No" I have no problem in both debug/release configurations.
4
4035
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.
5
5358
by: David++ | last post by:
Hi there, I have built a DLL in Visual C++ 6. When I build the DLL it builds fine for the debug version of the DLL (and this DLL works fine), however, I seem unable to build a Release version of the DLL. If I do a 'Batch Build' and select both Debug and Relase versions for building it will build the debug version but throws up errors for the Release version. For example, the output I get for a Batch Build is this - ...
6
3665
by: pauldepstein | last post by:
To help me debug, I am writing a lot of information into a stream which I call debug. However, because of the large amount of time taken to print this information, I only want this printed while I am in debugging mode as indicated by a preprocessor directive: #define DEBUG In other words, I need code which says "Whenever I write debug <<
9
2333
by: Bern McCarty | last post by:
I am porting stuff from MEC++ syntax to the new C++/CLI syntax. Something that we did in the old syntax that proved to be very valuable was to make sure that the finalizer would purposefully generate an assertion failure for unoptimized, debug builds. We did this to find and fix cases where we were relying upon finalization rather than pro-active Dispose() calls. For classes that introduced IDisposable() into the class hierarchy...
0
9579
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, 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...
0
9422
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,...
0
10208
Oralloy
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...
0
10036
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8863
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, 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...
0
5294
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...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
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
3
2812
bsmnconsultancy
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...

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.