473,320 Members | 1,974 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,320 software developers and data experts.

REQ HowTo: Passing class specific char ptr through template declaration

How can you pass a string through a template parameter? I am trying
to avoid using the stream objects and need to pass in class specific
information at creation.

Any information would be helpful. Thanks,

dmille

i.e.

template<class T, const char *FMT>
class Foo
{
private :
T _x ;

public :
foo() {}
short scan_it( const char *src )
{
return sscanf( src, FMT, &_x ) ;
}
} ;

typedef Foo<long, "%ld"> LongFoo ;

....
LongFoo tmp ;

tmp.scan_it( "192" ) ;
Jul 19 '05 #1
1 2160
"Dave Miller" <dm******@hotmail.com> wrote...
How can you pass a string through a template parameter? I am trying
to avoid using the stream objects and need to pass in class specific
information at creation.

Any information would be helpful. Thanks,

dmille

i.e.

template<class T, const char *FMT>
class Foo
{
private :
T _x ;

public :
foo() {}
short scan_it( const char *src )
{
return sscanf( src, FMT, &_x ) ;
}
} ;

typedef Foo<long, "%ld"> LongFoo ;
You cannot use string literals as non-type template arguments.
Those things have to have external linkage. You should be able
to do

extern const char *PctLD = "%ld"; // if you need this in
// a header, initialise it
// only once in some source
// file
typedef Foo<long, PctLD> LongFoo;

...
LongFoo tmp ;

tmp.scan_it( "192" ) ;


Victor
Jul 19 '05 #2

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

Similar topics

5
by: nifsmith | last post by:
Hi I am trying to learn about Queues and use templates at the same time. I have written the following code and I am getting a link error, stating "unresolved external symbol, "int__cdecl...
2
by: gg | last post by:
I am facing some problems with following program. I am using aCC version 03.27 on HP-UX11. The command line I use to compile is - aCC -AA -I. TestTempMethods.C Can anybody pls suggest how to...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
40
by: Angus | last post by:
Hello I am writing a library which will write data to a user defined callback function. The function the user of my library will supply is: int (*callbackfunction)(const char*); In my...
1
by: farseerfc | last post by:
Hi, everyone here loves C++; As a student studying data structure, I'm writting a single list (with only one pointer to identity the next node in its node struct) simulating std::list like: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.