Understanding C++ template partial specialization with pointer datatype arguments
When I compile the below code, I am getting error as
Code:
template<typename T> T AddFun(T i, T j) {
return i + j;
}
template<> T* AddFun<T*>(T* i, T* j) {
return new T(*i + *j);
}
int main() {
int n = AddFun<int>(10, 20);
int i = 10, j = 20;
int* p = AddFun<int*>(&i, &j);
}
9: error: ‘T’ does not name a type
13: error: expected unqualified-id before ‘int’
If I change the prototype to
Code:
template<typename T> T* AddFun<T*>(T* i, T* j)
then I get the error as 9: error: function template partial specialization ‘AddFun<T*>’ is not allowed.
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
after some years of pause, im returning to c.
char *varname = "asd";
int *number = 4;
the above code is wrong, because its assigning a value to an unreserved space, or because its changing the address the pointer is pointing ?
thanks for the replys!! (3 Replies)
1. The problem statement, all variables and given/known data:
So I have to write a Bourne script that will add two numbers, taking only two arguments and informs the user when it is used incorrectly.
2. Relevant commands, code, scripts, algorithms:
It has to be done in sh. I think overall,... (3 Replies)
#include <stdio.h>
int main(int argc, char *argv) {
printf("%d\n", sizeof(argv));
return 0;
}
when I run the executable a.out after compiling the above program as:
a.out short (or) a.out "long double", I expected to get the output as 2 and 12, but I am always getting the size of... (2 Replies)
Hello, this is probably a simple request but I've been toying with it for a while.
I have a large list of devices and commands that were run with a script, now I have lines such as:
a-router-hostname-C#show ver
I want to print everything up to (and excluding) the # and everything after it... (3 Replies)
Hi,
I am creating a program with the C language that simulates the WC command in Unix. My program needs to count lines, bytes and words. I have not added the code to count bytes and words yet. I am having trouble understanding what the file option/flag '-' does. I can not visualize how it moves... (1 Reply)
Hi All,
I am new to unix but have a requirement wherein I need to separate datatype,length, and column name from input file which is of below format --
record
integer(10) empid;
string(25) name;
date("YYYY-MM-DD") dob;
decimal(10) salary;
end
now after getting datatype,its length and... (4 Replies)
I have a sourcefile which contains data as below.I want to check whether datatype,structure and date format looks good as mentioned.
Data is delemited by cydila .
Source file-Emp.txt
sno name phoneno dept joineddate
1 vivek 0861 CSE 2013-05-29 00:00:00
2 dinesh 123456 ECE ... (2 Replies)
I have sourcefile and structure of source file,i want to check whether datatype and length mention in emp.txt is same as source file.
Example:
in emp.txt first row contains sno number so in source file also first column should contain only number if data is other than number then that... (1 Reply)
I have a sourcefile which contains data as below.I want to check whether datatype,structure and date format looks good as mentioned.
Data is delemited by cydila Ç.
Source file-Emp.txt
snoÇnameÇphonenoÇdeptÇjoineddate
1ÇvivekÇ0861ÇCSEÇ2013-05-29 00:00:00
2ÇdineshÇ123456ÇECEÇ2013-05-29 00:00:00... (8 Replies)
Discussion started by: katakamvivek
8 Replies
LEARN ABOUT DEBIAN
redi
redi(3) Library Functions Manual redi(3)NAME
redi -
All PStreams classes are declared in namespace redi.
SYNOPSIS
Classes
struct pstreams
Common base class providing constants and typenames.
class basic_pstreambuf
Class template for stream buffer.
class pstream_common
Class template for common base class.
class basic_ipstream
Class template for Input PStreams.
class basic_opstream
Class template for Output PStreams.
class basic_pstream
Class template for Bidirectional PStreams.
class basic_rpstream
template for Restricted PStreams.
Typedefs
typedef basic_pstreambuf< char > pstreambuf
Type definition for common template specialisation.
typedef basic_ipstream< char > ipstream
Type definition for common template specialisation.
typedef basic_opstream< char > opstream
Type definition for common template specialisation.
typedef basic_pstream< char > pstream
Type definition for common template specialisation.
typedef basic_rpstream< char > rpstream
Type definition for common template specialisation.
Detailed Description
All PStreams classes are declared in namespace redi.
Like the standard iostreams, PStreams is a set of class templates, taking a character type and traits type. As with the standard streams
they are most likely to be used with char and the default traits type, so typedefs for this most common case are provided.
The pstream_common class template is not intended to be used directly, it is used internally to provide the common functionality for the
other stream classes.
Author
Generated automatically by Doxygen for PStreams from the source code.
PStreams Thu Nov 10 2011 redi(3)