In the new issue o
How do New Yorkers
Terry is known for
The invention rela
The new year has b
Mozilla has been t
The present invent
The goal of this p
Q:
How to use ng-
Bisphenol A and lo// (C) Copyright John Maddock 2006.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "../memory"
//[example_function
#include
using std::cout;
int main ()
{
// Create a block with an initializer.
// Note that we're using a static data member, which will be allocated in the data area,
// so we'll have to use malloc to obtain a pointer to the data.
// The contents of the memory block are copied, so that if it was also a managed type,
// it would be copied.
int x = 7;
char *p = (char *)(malloc(sizeof(int)));
*p = x;
// Invoke an overloaded function, note that it is not a template.
// Since there is only one parameter, we can omit the template parameter list.
cout << x << '\n';
// Invoke a templated overloaded function.
cout << f(&x) << '\n';
// Print the memory block and free it.
cout << "Block contains:\n";
for(char *q = (char *)x; q != p; q++)
cout << ' ' << *q;
cout << '\n';
free(p);
}
//]
void f(int* x)
{
cout << "Inside function!\n";
}
//[fcontext_function
#include
using std::cout;
int main ()
{
// Create a block with an initializer.
// Note that we're using a static data member, which will be allocated in the data area,
// so we'll have to use malloc to obtain a pointer to the data.
// The contents of the memory block are copied, so that if it was also a managed type,
// it would be copied.
int x = 7;
char *p = (char *)(malloc(sizeof(int)));
*p = x;
// Invoke an overloaded function, note that it is not a template.
// Since there is only one parameter, we can omit the template parameter list.
cout << x << '\n';
// Invoke a templated overloaded function.
f(&x);
// Print the memory block and free it.
cout << "Block contains:\n";
for(char *q = (char *)x; q != p; q++)
cout << ' ' << *q;
cout << '\n';
free(p);
}
//]
void f(int* x)
{
cout << "Inside function!\n";
}
//[class_function
class X
{
// Create a block with an initializer.
// Note that we're using a static data member, which will be allocated in the data area,
// so we'll have to use malloc to obtain a pointer to the data.
// The contents of the memory block are copied, so that if it was also a managed type,
// it would be copied.
int x;
};
//]
class X
{
// Create a block with an initializer.
// Note that we're using a static data member, which will be allocated in the data area,
// so we'll have to use malloc to obtain a pointer to the data.
// The contents of the memory block are copied, so that if it was also a managed type,
// it would be copied.
int x;
};
//]
//[class_data_member_template
template
class MyClass
{
T m;
};
//]
//[class_class_data_member_template
template
class MyClass2
{
T m;
};
//]
//[class_private_data_member_template
template
class MyPrivateClass
{
T m;
public:
MyPrivateClass(T a):m(a){}
};
//]
//[class_member_template_definition_and_declaration
template
void member(T);
template
void member(T) { }
//]
template
void X::member(T x)
{ }
//[class_member_definition_and_declaration
template
void X::member(T x)
{ }
//]
template
void member(T x)
{ }
//[template_declaration
//]
template class T, typename X>
T *function(X x)
{ return new T (); }
//]
//[typedef_declaration
template
class MyClass
{
typedef T Tobj;
};
//]
//[typedef_declaration_and_definition
template
class MyClass2
{
typedef T Tobj;
};
//]
//[typedef_declaration_and_definition_declaration
template
typename MyClass::Tobj member;
//]
template
typename MyClass2::Tobj member;
//[typedef_definition_declaration
template
class MyClass3
{
typedef T Tobj;
};
//]
//[typedef_definition
template
class MyClass4
{
typedef T Tobj;
};
//]