I have a simple class for which I want to overload operator as below
class MyClass
{
public:
int first;
template <typename T>
T operator () () const { return first; }
};
And the somewhere else I have
MyClass obj;
int i = obj(); // This gives me an error saying could not deduce
// template argum...
When I'm writing a function in a template class how can I find out what my T is?
e.g.
template <typename T>
ostream& operator << (ostream &out,Vector<T>& vec)
{
if (typename T == int)
}
How can I write the above if statement so it works?
...
The code below does not compile in Visual C++ 2005.
class SomeClass {
public: boost::function<void()> func;
SomeClass(boost::function<void()> &func): func(func) { }
};
void someFunc() {
std::cout << "someFunc" << std::endl;
}
int main() {
SomeClass sc(boost::function<void()>(&someFunc));
sc.func(); // error C2228: ...
I'm in the process of building a web application using cherrypy.
What template technology do you recommend I use?
...
In C++, if you define this function in header.hpp
void incAndShow()
{
static int myStaticVar = 0;
std::cout << ++myStaticVar << " " << std::endl;
}
and you include header.hpp in at least two .cpp files. Then you will have multiple definition of incAndShow(). Which is expected. However, if you add a template to the function
templa...
According to this article from Herb Sutter, one should always pick Class Specializing over Function Overload and definitely over Specialized Function Templates.
The reason is that
Specializations don't overload. Overload resolution only selects a base template (or a nontemplate function, if one is available). Only after it's been ...
I don't understand what is wrong with this code.
gcc reports "Client.h:29: error: expected template-name before '<' token"
As far as I'm aware I'm followed the template syntax correctly, but it could be that the error message is confusing me and is not the problem
client.h
class Client : public BaseDll<DllClient> [line 29]
{
..snip.....
I've got some code where I would like to build a vector of elements using the mapped values in a map. The code below works fine in Visual Studio (and seems legit as far as I can tell), but g++ disagrees.
template<class PAIR>
typename PAIR::second_type foo(const PAIR& arg)
{
return (arg.second);
}
class A
{
private:
typedef std...
I am trying to write a C++ template function that will throw a runtime exception on integer overflow in casts between different integral types, with different widths, and possible signed/unsigned mismatch. For these purposes I'm not concerned with casting from floating-point types to integral types, nor other object-to-object conversions...
Hello Everyone,
I am trying to make a range control which is basically a slider control with an extra thumb. The only code I found for one already built is here.
http://www.codeplex.com/AvalonControlsLib
For the life of me I cannot get a tooltip to show up above each thumb (with the current value) while it is being moved. It will sh...
Been away from C++ for a few years and am getting a linker error from the following code:
Gene.h
#ifndef GENE_H_INCLUDED
#define GENE_H_INCLUDED
template <typename T>
class Gene {
public:
T getValue();
void setValue(T value);
void setRange(T min, T max);
private:
T value;
T minValue;
T maxValue;
};
#e...
Hi All,
Could someone please explain to me why I'm getting an ActionView::TemplateError when I try to use AJAX to update the interface while using the following code:
CODE
I have the following structure: Site -> Building -> Control. Each loops through it's collection of items and renders a partial for each. From Site to Building wo...
How to learn c++ generic programming and template? Recommend some good books about this topic.
...
Hi everyone, i have situation like this:
class IData
{
virtual void get() = 0;
virtual void set() = 0;
}
BOOST_ASSUME_IS_ABSTRACT(IData)
BOOST_EXPORT_CLASS(IData)
template<typename T>
class ConcreteData : public IData
{
public:
protected:
template<typename Archive>
void serialize(Archive& ar, const unsigned version)
{
ar &...
I have a C++ application that can be simplified to something like this:
class AbstractWidget {
public:
virtual ~AbstractWidget() {}
virtual void foo() {}
virtual void bar() {}
// (other virtual methods)
};
class WidgetCollection {
private:
vector<AbstractWidget*> widgets;
public:
void addWidget(AbstractWidget* widget) {...
Looking for something simple (like Smarty for PHP or erb in Rails), but that will allow nesting templates inside each other. Does App Engine have anything built-in, or will I need to look into something separate (like Velocity?)?
Thanks.
...
For creating algorithm template function I need to know whether x or X (and y or Y) in class that is template argument. It may by useful when using my function for MFC CPoint class or GDI+ PointF class or some others. All of them use different x in them. My solution could be reduces to the following code:
template<int> struct TT {typed...
How do I update the factory layout templates in Proficy Change Management (i.e. where are they located when checked out?). e.g. generic.htm?
...
When researching an answer to a question (based on this answer) I tried to do the following:
template <class T>
class friendly {
friend class T;
};
friendly<string> howdy;
This fails to compile with the following error:
error: template parameter "T" may not be used in an
elaborated type specifier
frien...
I was wondering if it is possible to change the return type of a function based on the type of variable it is being assigned to. Here's a quick example of what I mean.
I want to create a function that parses a variable of int, bool, or float from a string. For example...
Int value = parse("37");
Float value = parse("3.14");
Bool value ...