Hi,
I want to do a vector, that is the same in every template class, is it
possible?
Example:
....
class temp<int>.... static vector A;
class temp<float>... static vector A;
Now I want to get acces to A without using <...>.
Thank you. 6 1525
Nils wrote: Hi, I want to do a vector, that is the same in every template class, is it possible? Example: ... class temp<int>.... static vector A; class temp<float>... static vector A;
What C++ code is that supposed to represent? Now I want to get acces to A without using <...>. Thank you.
Ok, here real c++ code :=)
template <class T>
class test{
public:
static vector vec;
};
test<float> f;
test<int> i;
Now I want to get the vector:
f<float>::vec and i<int>::vec
to be the same, and also acces them without explicit using of the template
class, here float and int.
I know like it is above it is not possible. But is there a way to make it
possible?
"Jeff Schwab" <je******@comcast.net> schrieb im Newsbeitrag
news:5q********************@comcast.com... Nils wrote: Hi, I want to do a vector, that is the same in every template class, is it possible? Example: ... class temp<int>.... static vector A; class temp<float>... static vector A;
What C++ code is that supposed to represent?
Now I want to get acces to A without using <...>. Thank you.
Nils wrote: Ok, here real c++ code :=)
template <class T> class test{ public: static vector vec;
Is "vector" a type unrelated to the class template of the same name?
}; test<float> f; test<int> i;
Now I want to get the vector: f<float>::vec and i<int>::vec to be the same, and also acces them without explicit using of the template class, here float and int. I know like it is above it is not possible. But is there a way to make it possible?
Somebody (not me) proposed a solution here recently that was along these
lines:
typedef char vector; // For all I know.
struct vec_base
{
vector vec;
};
template< typename T >
struct test: vec_base
{
};
int main( )
{
test<float> f;
test<int> i;
f.vec = 'f';
i.vec = 'i';
}
"Jeff Schwab" <je******@comcast.net> schrieb im Newsbeitrag news:5q********************@comcast.com...
Nils wrote:
Hi, I want to do a vector, that is the same in every template class, is it possible? Example: ... class temp<int>.... static vector A; class temp<float>... static vector A;
What C++ code is that supposed to represent?
Now I want to get acces to A without using <...>. Thank you.
"Nils" <sl***@web.de> wrote... Ok, here real c++ code :=)
"Real"? template <class T> class test{ public: static vector vec;
'vector' of what? Or do you mean, say, a string?
}; test<float> f; test<int> i;
Now I want to get the vector: f<float>::vec and i<int>::vec to be the same, and also acces them without explicit using of the template class, here float and int. I know like it is above it is not possible. But is there a way to make it possible?
-------------------
template<class T>
class test {
public:
static string& commonstring; // note: a reference
};
extern string commonstring; // you will have to define it somewhere
template<class T> string& test<T>::commonstring = ::commonstring;
-------------------
Victor
On Tue, 6 Jan 2004 22:30:11 +0100 in comp.lang.c++, "Nils"
<sl***@web.de> was alleged to have written: Hi, I want to do a vector, that is the same in every template class, is it possible? Example: ... class temp<int>.... static vector A; class temp<float>... static vector A;
Every instantiation of a class template is a different class.
They don't share anything.
If you want them to share something, one possible answer is to derive
the template class(s) from a base class, and make the shared thing
static protected in the base class. It's not perfect.
Jeff Schwab wrote: Nils wrote:
Ok, here real c++ code :=)
template <class T> class test{ public: static vector vec;
Is "vector" a type unrelated to the class template of the same name?
}; test<float> f; test<int> i;
Now I want to get the vector: f<float>::vec and i<int>::vec to be the same, and also acces them without explicit using of the template class, here float and int. I know like it is above it is not possible. But is there a way to make it possible?
Somebody (not me) proposed a solution here recently that was along these lines:
typedef char vector; // For all I know.
struct vec_base {
static vector vec; };
char vec_base::vec = '\0'; template< typename T > struct test: vec_base {
};
int main( ) { test<float> f; test<int> i;
f.vec = 'f'; i.vec = 'i'; }
"Jeff Schwab" <je******@comcast.net> schrieb im Newsbeitrag news:5q********************@comcast.com...
Nils wrote:
Hi, I want to do a vector, that is the same in every template class, is it possible? Example: ... class temp<int>.... static vector A; class temp<float>... static vector A;
What C++ code is that supposed to represent?
Now I want to get acces to A without using <...>. Thank you.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nils |
last post by:
Hi,
Ich have a template class and want to initialize a static variable, that is
available for all objekts of the template class, doesn't matter what
template parameter is used.
Can someone please...
|
by: Graham Dumpleton |
last post by:
When you have a template class with a static member variable, ie.,
template<typename T>
class handle
{
public:
static void* id() { return &id_; }
private:
static int id_;
};
|
by: Drew McCormack |
last post by:
I have a C++ template class which contains a static variable whose
construction registers the class with a map. Something like this:
template <typename T>
class M {
static Registrar<M>...
|
by: Eric |
last post by:
I have a static class member variable as follows:
struct A
{
static void Set (int i) { v = i; }
static int& Get () { return v; }
static int v;
};
int A::v; // define A::v in the cpp file
|
by: Erik Arner |
last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run
into all sorts of troubles that I'm sure depends on my lack of proper
understanding of C++. I would now like to get it right...
|
by: Nils |
last post by:
Hi.
I ahve three classes A,B,C, where B and C are derived from A.
A:>B,C.
Furthermore each class has an static int variable with name id,
static int id;
Besides that the class A implements the...
|
by: Jon Slaughter |
last post by:
Is there any way to declare a member of a base class to make the itself in
the derived class to be static?
i.e., I have two classes
class Base
{
protected:
char *name;
|
by: Diebels |
last post by:
Hi,
I have some problems using static variables which results in a core
dump. I have attached code and coredump to the end of my message.
I am trying to implement a kind of factory design. I...
|
by: Juha Nieminen |
last post by:
As we know, the keyword "inline" is a bit misleading because its
meaning has changed in practice. In most modern compilers it has
completely lost its meaning of "a hint for the compiler to inline...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
| |