// THIS CODE:
template<class Tclass C
{
public:
C()
{
T t;
data[0] = t;
}
T data[5];
};
int main(int, char**)
{
C<doublec;
return 0;
}
// END CODE
yields error: local variable 't' used without being initialized.
What can I do to make it work with built in variables, initialized as
0?
Must I really specialize for every built in type?
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);} 8 1448
Gernot Frisch wrote:
// THIS CODE:
template<class Tclass C
{
public:
C()
{
T t;
data[0] = t;
}
T data[5];
};
int main(int, char**)
{
C<doublec;
return 0;
}
// END CODE
yields error: local variable 't' used without being initialized.
What can I do to make it work with built in variables, initialized as
0?
What do you want it to do? Is data[0] = T(); what you want?
--
Ian Collins.
"Gernot Frisch" <Me@Privacy.netwrote in message
news:5d*************@mid.individual.net...
>
// THIS CODE:
template<class Tclass C
{
public:
C()
{
T t;
T t();
data[0] = t;
Although you could just do it here:
data[0] = t();
}
T data[5];
};
int main(int, char**)
{
C<doublec;
return 0;
}
// END CODE
yields error: local variable 't' used without being initialized.
What can I do to make it work with built in variables, initialized as 0?
Must I really specialize for every built in type?
Gernot Frisch wrote:
>
// THIS CODE:
template<class Tclass C
{
public:
C()
{
T t;
data[0] = t;
What about ditching the variable t altogether:
data[0] = T();
}
T data[5];
};
int main(int, char**)
{
C<doublec;
return 0;
}
// END CODE
yields error: local variable 't' used without being initialized.
What can I do to make it work with built in variables, initialized as
0?
Must I really specialize for every built in type?
No.
Best
Kai-Uwe Bux
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:4d*************@newsfe06.lga...
>
"Gernot Frisch" <Me@Privacy.netwrote in message
news:5d*************@mid.individual.net...
>> // THIS CODE: template<class Tclass C { public: C() { T t;
T t();
> data[0] = t;
Although you could just do it here:
data[0] = t();
er,
data[0] = T();
is what I meant.
>
>}
T data[5]; };
int main(int, char**) { C<doublec; return 0; }
// END CODE
yields error: local variable 't' used without being initialized. What can I do to make it work with built in variables, initialized as 0?
Must I really specialize for every built in type?
>What can I do to make it work with built in variables, initialized as 0?
What do you want it to do? Is data[0] = T(); what you want?
Doh! thank you
T t();
didn't work for <unsigned char>. It's trying to assign a function
then.
Ian's solution did it, though.
Thx for quick response.
On 21 Jun, 09:07, "Gernot Frisch" <M...@Privacy.netwrote:
T t();
didn't work for <unsigned char>. It's trying to assign a function
then.
not just for unsigned char.
T t();
declares function T (*)(void).
you either do
T t = T();
data[0] = t;
or
data[0] = T();
Ian's solution did it, though.
Thx for quick response.
check boost::value_intialized if you have to do
the same for non POD types.
regards
DS
Jim Langston <ta*******@rocketmail.comwrote:
"Gernot Frisch" <Me@Privacy.netwrote in message
news:5d*************@mid.individual.net...
>> // THIS CODE: template<class Tclass C { public: C() { T t;
T t();
This will declare a function called 't' that takes no parameters and
returns a T.
> data[0] = t;
Although you could just do it here:
data[0] = t();
data[0] = T(); as others have mentioned (including yourself in a later
post).
--
Marcus Kwok
Replace 'invalid' with 'net' to reply This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Blue |
last post by:
I've been relying on gcc compiling this but now it doesn't so I'm
hoping to learn the right way.
See the header below.
TCHAR Message = TEXT("Press a Key to Change Setting...");
this basicly...
|
by: Marcin Kalicinski |
last post by:
Hi,
void f()
{
int i1; // i1 now holds undefined value
int i2 = int(); // i2 now holds 0
}
Is the above true?
|
by: Charles Stapleton |
last post by:
Given the folowing class
class Ctest{
public:
Ctest( int i, int j) :a(i) { b = j; }
private:
int a, b;
}
When creating an object of type Ctest, what advantage is there to setting
|
by: lovecreatesbeauty |
last post by:
Prof. Bjarne Stroustrup said "built-in data types have default
constructor" at §10.4.2 in `TC++PL, special ed.'.
He also said that "built-in data types are not classes" at §11.4 in
`TC++PL,...
|
by: Alexander Stippler |
last post by:
Hello,
I have some class members of built-in type (to be exact: int) and wonder
about the initialization behaviour of gcc4.0.
I thought, these members would be implicitly be initialized to zero...
|
by: asdf |
last post by:
The oder of member initialization is the order in which the members are
defined.
So the following code is problematic:
class X{
int i;
int j;
public:
X(int val):j(val),i(j){}
|
by: Jess |
last post by:
Hello,
I understand the default-initialization happens if we don't initialize
an object explicitly. I think for an object of a class type, the
value is determined by the constructor, and for...
|
by: akomiakov |
last post by:
Is there a technical reason why one can't initialize a cost static non-
integral data member in a class?
|
by: tonytech08 |
last post by:
How valuable is it that class objects behave like built-in types? I
appears that the whole "constructor doesn't return a value because
they are called by the compiler" thing is to enable...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
| |