C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

tnt library curiosity

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
kwijibo28
Guest





PostPosted: Tue Mar 29, 2005 10:02 pm    Post subject: tnt library curiosity Reply with quote



Hi all,

I am considering using the TNT library for some application.

http://math.nist.gov/tnt/

While reading the online documentation they state that you can create
and initialize an Array2D class the following way:

Array2D< double > A(M,N) = 0.0; /* create MxN array; all zeros */ (1)

http://math.nist.gov/tnt/examples.html

When I saw this I was a little intrigue. Is it possible to create an
instance using Array2D<double>(int,int) constructor and in the same
expression use the operator=(double) to assign its content? Or perhaps
this is just alternative syntax for calling the following constructor:

Array2D< double > A(M,N,0.0); (2)

which is provided by the class Array2D<double>.

Anyway I've tried to compile line (1) on my compiler and it failed,
just as I expect it. Compiler is expecting a semicolon after the
closing parenthesis. Even if TNT documentation say it should compile.

Another way to achieve the same thing would be to write something
like:

Array2D< double > A(M,N); (3a)
A = 0.0; (3b)

Is my compiler faulty in this regard or TNT documentation erronous? I
must admit the syntax of (1) is more elegant than (2) or (3). But I'm
not sure this is valid C++. If (1) is equivalent to (2) than maybe all
these years I could have write this:

std::vector<int> a(10) = 100; instead of
std::vector<int> a(10,100);

Any comments on this would appreciated.

Kwijibo28

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Wed Mar 30, 2005 11:21 pm    Post subject: Re: tnt library curiosity Reply with quote



kwijibo28 wrote:

Quote:
I am considering using the TNT library for some application.

http://math.nist.gov/tnt/

While reading the online documentation they state that you can
create and initialize an Array2D class the following way:

Array2D< double > A(M,N) = 0.0; /* create MxN array; all zeros */ (1)

In a declaration "Array2D< double > A", there are two ways to
initialize: "(...)" or " = ...". They are exclusive: you can
use one, or the other (or neither), but not both.

As far as I know, this has always been the case.

Quote:
http://math.nist.gov/tnt/examples.html

When I saw this I was a little intrigue. Is it possible to
create an instance using Array2D<double>(int,int) constructor
and in the same expression use the operator=(double) to assign
its content?

No. A declaration is not an expression. Certain types of
expressions can occur in a declaration, but the '=' immediately
following what is being declared is NOT an operator, but simple
punctuation, and is NOT part of the initialization expression.
The language syntax allows two forms of initialization, but not
both.

Quote:
Or perhaps this is just alternative syntax for calling the
following constructor:

Array2D< double > A(M,N,0.0); (2)

No.

Quote:
which is provided by the class Array2D<double>.

Anyway I've tried to compile line (1) on my compiler and it
failed, just as I expect it. Compiler is expecting a
semicolon after the closing parenthesis. Even if TNT
documentation say it should compile.

Another way to achieve the same thing would be to write
something like:

Array2D< double > A(M,N); (3a)
A = 0.0; (3b)

Is my compiler faulty in this regard or TNT documentation
erronous?

The documentation is erroneous. (Sort of makes you wonder if
they ever actually tested the code.)

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
msalters
Guest





PostPosted: Wed Mar 30, 2005 11:25 pm    Post subject: Re: tnt library curiosity Reply with quote




kwijibo28 wrote:
Quote:
Hi all,

I am considering using the TNT library for some application.

http://math.nist.gov/tnt/

While reading the online documentation they state that you can create
and initialize an Array2D class the following way:

Array2D< double > A(M,N) = 0.0; /* create MxN array; all zeros */ (1)

http://math.nist.gov/tnt/examples.html

When I saw this I was a little intrigue. Is it possible to create an
instance using Array2D<double>(int,int) constructor and in the same
expression use the operator=(double) to assign its content?

No, the statement is a declaration. The = in a declaration
does not refer to operator=, but provides the argument for
the ctor of the object on the left of the = . However,
what appears on the left ("A(M,N)") is not the name of
an object. Instead, it looks an object which is
constructed from the two the arguments M and N. (they're
not types, right?)

Quote:
Or perhaps this is just alternative syntax for calling
the following constructor:

Array2D< double > A(M,N,0.0); (2)

No.

Quote:
Anyway I've tried to compile line (1) on my compiler and it failed,
just as I expect it. Compiler is expecting a semicolon after the
closing parenthesis. Even if TNT documentation say it should compile.

Compiles tend to get these things right. Having a
semicolon where the compiler thinks it should be
makes it legal C++.

HTH,
Michiel Salters


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.