I've been trying to get a template that converts the characters in a string to upper case letters.
I need to do this several times throughout my program.
So i'll use a template.
template <string theString>
string strUpper( string theString )
{
int myLength = theString.length();
for( int sIndex=0; sIndex < myLength; sIndex++ )
...
I have a function declared like so:
template <typename T>
T read();
and defined like so:
template <typename T>
T packetreader::read() {
offset += sizeof(T);
return *(T*)(buf+offset-sizeof(T));
}
However, when I try to use it in my main() function:
packetreader reader;
reader.read<int>();
I get the following error from ...
I'm using libgc, a garbage collector for C and C++.
To make STL containers garbage collectible one must use the gc_allocator.
Instead of writing
std::vector<MyType>
one has to write
std::vector<MyType,gc_allocator<MyType> >
Could there be a way to define something like
template<class T> typedef std::vector<T,gc_allocator<T> ...
#include <iostream>
using namespace std;
/*
TA <-- defines static function
/ \
| B <-- subclass TA, inherits it so B::StaticFunc can be used.
\ /
C <-- want to inherit static func from A, subclass B privately
*/
template <class T> class TA
{
public:
// return ptr to new insta...
I'm trying to use a typedef from a subclass in my project, I've isolated my problem in the example below.
Does anyone know where I'm going wrong?
template<typename Subclass>
class A {
public:
//Why doesn't it like this?
void action(typename Subclass::mytype var) {
(static_cast<Subclass*>(this))->do_action(var);
...
I am using a library that consists almost entirely of templated classes and functions in header files, like this:
// foo.h
template<class T>
class Foo {
Foo(){}
void computeXYZ() { /* heavy code */ }
};
template<class T>
void processFoo(const Foo<T>& foo) { /* more heavy code */ }
Now this is bad because compile times are unbearab...
We are using FW2.0 web application which is developed using VS2005.
Our win2003 server had Windows update on last week with FW3.5 SP1, after that we struck-up in web application login issue.
Basically our application works with both windows authentication as well anonyms
But after install the FW3.5 SP1, the windows integrated authenti...
I have purchase this book for our group in the company, perhaps, to improve our design skills and ultimately have a better programming practices. As I read it, I find, mostly, a set of nifty tricks that can be used with template, and not sure if it is worthwhile - and not detrimental-to incorporate it into our code thus introducing c...
Is it possible to set a Velocity reference to 'null' or 'undefined'?
The Velocity template language reference says
#set - Establishes the value of a reference
Format:
# [ { ] set [ } ] ( $ref = [ ", ' ]arg[ ", ' ] )
Usage:
$ref - The LHS of the assignment must be a variable reference or a property reference.
...
I have a code that parses some template files and when it finds a placeholder, it replaces it with a value. Something like:
<html>
<head>
<title>%title%</title>
</head>
<body bgcolor="%color%">
...etc.
In code, the parser finds those, calls this function:
string getContent(const string& name)
{
if (name == "title")
re...
I am trying to understand some C++ syntax:
template<class T>
class Foo
{
Foo();
template<class U>
Foo(const Foo<U>& other);
};
template<class T>
Foo<T>::Foo() { /*normal init*/ }
template<class T>
template<class U>
Foo<T>::Foo(const Foo<U>& other) { /*odd copy constructed Foo*/ }
So, I wrote code like this, and it happens...
The folowing code generates a syntax error at the line where the iterator is declared:
template <typename T>
class A
{
public:
struct B
{
int x, y, z;
};
void a()
{
std::map<int, B>::const_iterator itr; // error: ; expected before itr
}
std::vector<T> v;
std::map<int, B> m;
};
This o...
If I set TreeViewItem Background it highlights the header only. How can I highlight the whole line?
I have found a post almost solving a problem http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b04f73e2-0b10-4d97-a6da-64df2e30c21d/
But there are some problems:
1. It does not highlight the whole line
2. The tree has XP style on...
Being a dll newbie I have to ask the allmighty SO about something.
Say I explicitly instantiate a template class like this:
template class __declspec(dllexport) B<int>;
How do I use import this templated class again?
I've tried the adding the code below in my .cpp file where I want to use B
template class __declspec(dllimport) B<i...
I seem to recall reading about a way to 'reduce' the size of template spew in compiler errors associated with the boost libraries. My recollection is that it gives the template parameters nicer names than the compiler default naming (which is quite horrid).
Is this real, or did I dream about it? I've been trying to find where I read thi...
Is there a way to tell the compiler (g++ in my case) to not optimize certain code away, even if that code is not reachable? I just want those symbols in the object file.
Example: Here is a simple function, and I do want this function to be compiled, even if it's never called.
void foo(){
Foo<int> v;
}
If there is no official compil...
Just a quick and simple question, but couldn't find it in any documentation.
template <class T>
T* Some_Class<T>::Some_Static_Variable = NULL;
It compiles with g++, but I am not sure if this is valid usage. Is it?
...
I am trying to iterate through form.fields in a template and for:
{% for field in form.fields %}
{{ field }},
{% endfor %}
I am getting a list of the field names ("name, description...") instead of the html code that is rendered when using the following:
{{ form.name }}, {{ form.description }}
(the output in this case is:
<in...
One of my favorite features in Eclipse is the templates in PDT. In case you don't know what they are, think of writing "function" and having Eclipse write all the syntactical features and let you jump from variable to variable with a tap of the tab key. So I'm starting to do write AS3 in Eclipse and I miss having the templates at my fing...
Having such MarkupExtension
public class Extension1 : MarkupExtension
{
private static int _counter = 0;
public override object ProvideValue(IServiceProvider serviceProvider)
{
return string.Format("Item {0}", _counter++);
}
}
and this XAML
<ListBox>
<ListBoxItem Content="{my:Extension1}"></ListBoxItem>
<...