473,396 Members | 1,924 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.

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"<<endl; --------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 1394
On Sep 30, 2:46*pm, thomas <FreshTho...@gmail.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"<<endl; * * * * * ** --------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...@gmail.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 objektorientierter Datenverarbeitung
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...@gmail.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_type1c1;
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
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...
1
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...
9
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...
4
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....
1
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...
4
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' ...
5
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...
6
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...
9
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.