Any idea why line 57 fails? http://rafb.net/p/86JdGg61.html
gs = MyShutdown<Comp onent, T1, T2, T3>(this);
Errors:
shutdown1.cpp: In constructor `Component<T1, T2, T3>::Component( int)':
shutdown1.cpp:4 6: error: type/value mismatch at argument 1 in template
parameter list for `template<templ ate<class T1, class T2, class T3>
class Calling_Comp
onent, class T1, class T2, class T3class MyShutdown'
shutdown1.cpp:4 6: error: expected a class template, got
`Component<T1, T2, T3>'
#include <iostream>
#include <string>
using namespace std;
class Shutdown
{
virtual void begin()
{
cout << "shutdown" << endl;
exit(0);
}
};
Shutdown *gs;
template <template <class T1, class T2, class T3class
Calling_Compone nt, class T1, class T2, class T3>
class MyShutdown : public Shutdown
{
typedef Calling_Compone nt<T1, T2, T3Caller;
Caller& mCaller;
public:
MyShutdown(Call er& rCaller)
: mCaller(rCaller )
{
}
void begin()
{
cout << "MyShutdown caller # " << mCaller.mnId << endl;
exit(0);
}
};
template <typename T1, typename T2, typename T3>
class Component
{
public:
Component(int n)
: mnId(n)
{
gs = MyShutdown<Comp onent, T1, T2, T3>(this);
}
int mnId;
};
int main()
{
Component<int, int, stringc(5);
MyShutdown<Comp onent, int, int, strings(c);
s.begin();
} 1 5199 ga************@ gmail.com wrote:
Any idea why line 57 fails? http://rafb.net/p/86JdGg61.html
....
MyShutdown(Call er& rCaller)
do you mean to be passing a reference or a pointer ?
: mCaller(rCaller )
{
}
void begin()
{
cout << "MyShutdown caller # " << mCaller.mnId << endl;
exit(0);
}
};
template <typename T1, typename T2, typename T3>
class Component
{
public:
Component(int n)
: mnId(n)
{
gs = MyShutdown<Comp onent, T1, T2, T3>(this);
Even though Component is an appropriate template, the compiler (rightly
or wrongly (i'm not sure) is interpreting Component as the specialized
type in this context. BTW - this is a pointer no a reference.
....
Here is code that compiles - not sure if it does what you want. Note
that <: has special meaning in C++ (look up digraph) so make sure you
leave a space between < and ::.
#include <iostream>
#include <string>
using namespace std;
class Shutdown
{
virtual void begin()
{
cout << "shutdown" << endl;
exit(0);
}
};
Shutdown *gs;
template <template <class, class, classclass
Calling_Compone nt, class T1, class T2, class T3>
class MyShutdown : public Shutdown
{
typedef Calling_Compone nt<T1, T2, T3Caller;
Caller& mCaller;
public:
MyShutdown(Call er& rCaller)
: mCaller(rCaller )
{
}
void begin()
{
cout << "MyShutdown caller # " << mCaller.mnId << endl;
exit(0);
}
};
template <typename T1, typename T2, typename T3>
class Component
{
public:
Component(int n)
: mnId(n)
{
gs = new MyShutdown</* space */::Component, T1, T2, T3>(*this);
}
int mnId;
};
//} //namespace XX
int main()
{
Component<int, int, stringc(5);
MyShutdown< Component, int, int, strings(c);
s.begin();
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Neil Zanella |
last post by:
Hello,
I would like to ask how come the design of C++ includes
std::pair. First of all I don't think many programmers
would use it. For starters, what the first and second
members are depends on what you are using the pair
for. For instance if I am using coordinates in two
dimensional space then I like to use x and y. So
I might as well define my own struct with x and
y members in it and create a constructor so
|
by: Bart Plessers \(artabel\) |
last post by:
Hello,
I need a style that defines
-table cellspacing
-table cellpading
-alignment
I tried
<table class="TBLpageframe">
<tr class="TRpageframe">
|
by: CFG |
last post by:
Is there a ready-to-use C++ smart pointer class working on top of COM
reference counting mechanism.
Did anyone manage to tailor one of the available smart pointer libs to
handle COM objects?
Probably I can use boost::shared_ptr<T> with custom deleter -
which calls obj->Release() instead of delete obj;
But this workaround is not safe and wasteful (we have two separate
reference counters around: first counter is an internal COM's one,...
|
by: jstanforth |
last post by:
This is probably a very obvious question, but I'm not clear on what
operators need to be implemented for std::map.find() to work. For
example, I have a class MyString that wraps std::string, and which also
implements ==, <, <=, >, >=, etc. (Those operators are tested and
working correctly.)
If I assign map = "world", it saves the MyString's correctly
in the map. But a subsequent call to map.find("hello") returns
map.end(). Even more...
|
by: Eric Lilja |
last post by:
Hello, I was working on a program where I needed to take a vector storing
objects of type std::string and convert each object to an int and store the
ints in another vector. I decided that I should create a templated function
for this because I've done similar things before and expect to do similar
things again (i.e., converting a collection of one type to a collection of
another type).
This is my test program, it compiles but if I try to...
| |
by: Joseph Turian |
last post by:
Some function requires a vector<const foo*> argument.
How can I cast a vector<foo*> to vector<const foo*>?
Thanks!
Joseph
|
by: Peted |
last post by:
I have the following code
public enum pdfFlags
{
PFD_DRAW_TO_WINDOW,
PFD_DRAW_TO_BITMAP,
PFD_SUPPORT_GDI,
PFD_SUPPORT_OPENGL,
PFD_GENERIC_ACCELERATED, PFD_GENERIC_FORMAT,
|
by: subramanian100in |
last post by:
Given two types T1 and T2, we can create
pair<T1, T2p(value1, value2);
where value1 and value2 are of types T1 and T2 respectively.
Suppose we want to assign a new pair<value to p. We can do it as
p = pair<T1, T2>(value3, value4);
where value3 and value4 are of types T1 and T2 respectively.
The last statement can also be written as
|
by: not_a_commie |
last post by:
I'm struggling here. Please help me complete this method:
Type ToFuncType(Type owningType, Type result)
{
return typeof(Func<typeof(owningType), typeof(result)>);
}
Or more generally, given a MethodInfo from GetGetMethod, what is the
fastest way to get a delegate to the method? I can hard-code the Func
type with Delegate.CreateDelegate and it does exactly what I want. I
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |