f



What's wrong with this code? 212848

Is this legal C++03 code:

template <class T>
struct A
{
    template<class U>
    A(int, long)
    {
    }
};

int main()
{
    A<int> a(2, 3L);
}

I have tried compiling this with g++ 3.4.6:
-----------------------------------------------------------
A.cpp: In function `int main()':
A.cpp:12: error: no matching function for call to `A<int>::A(int, long
int)'
A.cpp:3: note: candidates are: A<int>::A(const A<int>&)

It fails on Comeau as well:
--------------------------------------
"ComeauTest.c", line 4: warning: template parameter "U" is not used in
declaring the
           parameter types of function template "A<T>::A"
      template<class U>
                     ^

"ComeauTest.c", line 12: error: no instance of constructor "A<T>::A
[with T=int]"
           matches the argument list
             The argument types that you used are: (int, long)
      A<int> a(2, 3L);
               ^



I don't really understand why this should not work. Is it really
necessary for typename U to play a role to select the correct
constructor?

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

0
shri314
5/10/2009 4:38:03 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8506) is leader. Post Follow

8 Replies
345 Views

Similar Articles

[PageSpeed] 38

On May 10, 4:38 pm, "shri...@gmail.com" <shri...@gmail.com> wrote:
> Is this legal C++03 code:
>
> template <class T>
> struct A
> {
>     template<class U>
>     A(int, long)
>     {
>     }
>
> };
>
> int main()
> {
>     A<int> a(2, 3L);
>
> }
>
> I have tried compiling this with g++ 3.4.6:
> -----------------------------------------------------------
> A.cpp: In function `int main()':
> A.cpp:12: error: no matching function for call to `A<int>::A(int, long
> int)'
> A.cpp:3: note: candidates are: A<int>::A(const A<int>&)
>
> It fails on Comeau as well:
> --------------------------------------
> "ComeauTest.c", line 4: warning: template parameter "U" is not used in
> declaring the
>            parameter types of function template "A<T>::A"
>       template<class U>
>                      ^
>
> "ComeauTest.c", line 12: error: no instance of constructor "A<T>::A
> [with T=int]"
>            matches the argument list
>              The argument types that you used are: (int, long)
>       A<int> a(2, 3L);
>                ^
>
> I don't really understand why this should not work. Is it really
> necessary for typename U to play a role to select the correct
> constructor?

Yes, since it still has to know what type U will be for the particular
call. Even if it's seemingly unused, there are many reasons why it
might matter - for example, if you have a local static variable inside
that constructor.


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

0
Pavel
5/11/2009 5:13:34 AM
On May 11, 7:38 am, "shri...@gmail.com" <shri...@gmail.com> wrote:
>
> template <class T>
> struct A
> {
>     template<class U>
You did not use the typename U.
>     A(int, long)
How about try "A(int, U)" ?
>     {
>     }
>
> };
>
> int main()
> {
>     A<int> a(2, 3L);
>
> }


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

0
Linlin
5/11/2009 5:40:03 AM
shri314@gmail.com wrote:
> template <class T>
> struct A
> {
>     template<class U>
>     A(int, long)
>     {
>     }
> };
> 
> int main()
> {
>     A<int> a(2, 3L);
> }

Question: what is 'U' in the above constructor call? If you can't tell, how
should the compiler?

> I don't really understand why this should not work. Is it really
> necessary for typename U to play a role to select the correct
> constructor?

No, generally not. However, if the type can not be inferred from the
parameters, it must be given explicitly. I haven't tested it, but I would
try

  A<int> a<...>(2, 3L);

...of course substituting '...' with some type.

Notes:
1. I don't think it matters in any way that A itself is a template, only
that the constructor is one.
2. The above solution sure works for a function:

   template<typename T> T default_value() { return T(); }
   // doesn't compile, T is unknown
   default_value();
   // works
   default_value<float>();

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932


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

0
Ulrich
5/11/2009 8:40:51 AM
On May 11, 4:38 am, "shri...@gmail.com" <shri...@gmail.com> wrote:
> Is this legal C++03 code:
>
> template <class T>
> struct A
> {
>     template<class U>
>     A(int, long)
>     {
>     }
>
> };
>
> int main()
> {
>     A<int> a(2, 3L);
>
> }
>
> I have tried compiling this with g++ 3.4.6:
> -----------------------------------------------------------
> A.cpp: In function `int main()':
> A.cpp:12: error: no matching function for call to `A<int>::A(int, long
> int)'
> A.cpp:3: note: candidates are: A<int>::A(const A<int>&)
>
> It fails on Comeau as well:
> --------------------------------------
> "ComeauTest.c", line 4: warning: template parameter "U" is not used in
> declaring the
>            parameter types of function template "A<T>::A"
>       template<class U>
>                      ^
>
> "ComeauTest.c", line 12: error: no instance of constructor "A<T>::A
> [with T=int]"
>            matches the argument list
>              The argument types that you used are: (int, long)
>       A<int> a(2, 3L);
>                ^
>
> I don't really understand why this should not work. Is it really
> necessary for typename U to play a role to select the correct
> constructor?
>

Misconception:
Whenever we define any template function with same the name as that of
class, is a constructor.

Reality:
No that is not constructor. Constructor can never be template.

Reason:
For any specific class constructor is remain same

Here for A<T> [T=int] we can have several function template<class U> A
(int, long) for [U=Any type].

But we instantiating object from A<T> [T=int] with parameter as if
this class has such parameterized constructor. But in reality this
class has only two constructor default and copy constructor which
compiler given.


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

0
mail
5/11/2009 9:40:01 AM
On May 11, 8:40 pm, Ulrich Eckhardt <eckha...@satorlaser.com> wrote:
> shri...@gmail.com wrote:
> > template <class T>
> > struct A
> > {
> >     template<class U>
> >     A(int, long)
> >     {
> >     }
> > };
> >
> > int main()
> > {
> >     A<int> a(2, 3L);
> > }
>
> Question: what is 'U' in the above constructor call? If you can't tell,
how
> should the compiler?
>
> > I don't really understand why this should not work. Is it really
> > necessary for typename U to play a role to select the correct
> > constructor?
>
> No, generally not. However, if the type can not be inferred from the
> parameters, it must be given explicitly. I haven't tested it, but I would
> try
>
>   A<int> a<...>(2, 3L);
>

First - thanks for answering my question. It is correct that compiler
can't tell what U is, but there seems to be no way to specify it
explicitly either. I have tried the code above - it turns out to be a
syntax error. I even unsuccessfully tried other combinations of
disambiguation with "template" keyword for disabiguation.

A<int> a<char>(2, 3L);

A.cpp: In function `int main()':
A.cpp:12: error: expected initializer before '<' token

Neither does this:
A<int>::A<int> a<char>(2, 3L);

Neither does this:
A<int>::template A<char> a(2, 3L);

And some more that I have not listed here.

> ..of course substituting '...' with some type.
>
> Notes:
> 1. I don't think it matters in any way that A itself is a template, only
> that the constructor is one.

This is true.

> 2. The above solution sure works for a function:
>
>    template<typename T> T default_value() { return T(); }
>    // doesn't compile, T is unknown
>    default_value();
>    // works
>    default_value<float>();
>

This sure works as expected for functions.

> Uli
>
> --
> Sator Laser GmbH
> Gesch�ftsf�hrer: Thorsten F�cking, Amtsgericht Hamburg HR B62 932
>


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

0
shri314
5/11/2009 3:00:37 PM
shri314@gmail.com wrote:
> On May 11, 8:40 pm, Ulrich Eckhardt <eckha...@satorlaser.com> wrote:
>> shri...@gmail.com wrote:
>>> template <class T>
>>> struct A
>>> {
>>>     template<class U>
>>>     A(int, long)
>>>     {
>>>     }
>>> };
>>>
>>> int main()
>>> {
>>>     A<int> a(2, 3L);
>>> }
>> Question: what is 'U' in the above constructor call? If you can't tell,
> how
>> should the compiler?
>>
>>> I don't really understand why this should not work. Is it really
>>> necessary for typename U to play a role to select the correct
>>> constructor?
>> No, generally not. However, if the type can not be inferred from the
>> parameters, it must be given explicitly. I haven't tested it, but I would
>> try
>>
>>   A<int> a<...>(2, 3L);
>>
> 
> First - thanks for answering my question. It is correct that compiler
> can't tell what U is, but there seems to be no way to specify it
> explicitly either. I have tried the code above - it turns out to be a
> syntax error. I even unsuccessfully tried other combinations of
> disambiguation with "template" keyword for disabiguation.

Judging by the following posts, it seems as if you may be there a long
time trying to find a way that works:

http://learningcppisfun.blogspot.com/2007/02/constructor-templates-and-explicit.html
http://www.cpptalk.net/how-do-i-pass-explicit-template-arguments-to-a-templated-con-vt11726.html

The relevant bit (from the first page) is:

"Here is a note from the C++ standards 2005 draft that is quite
self-explantory: (section 14.8.1 paragraph 7)

[NOTE]

[ Note: because the explicit template argument list follows the function
template name, and because conversion member function templates and
constructor member function templates are called without using a
function name, there is no way to provide an explicit template argument
list for these function templates. �end note ]"

Regards,
Stu

> A<int> a<char>(2, 3L);
> 
> A.cpp: In function `int main()':
> A.cpp:12: error: expected initializer before '<' token
> 
> Neither does this:
> A<int>::A<int> a<char>(2, 3L);
> 
> Neither does this:
> A<int>::template A<char> a(2, 3L);
> 
> And some more that I have not listed here.
> 
>> ..of course substituting '...' with some type.
>>
>> Notes:
>> 1. I don't think it matters in any way that A itself is a template, only
>> that the constructor is one.
> 
> This is true.
> 
>> 2. The above solution sure works for a function:
>>
>>    template<typename T> T default_value() { return T(); }
>>    // doesn't compile, T is unknown
>>    default_value();
>>    // works
>>    default_value<float>();
>>
> 
> This sure works as expected for functions.
> 
>> Uli
>>
>> --
>> Sator Laser GmbH
>> Gesch�ftsf�hrer: Thorsten F�cking, Amtsgericht Hamburg HR B62 932


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

0
Stuart
5/12/2009 2:17:32 AM
On May 11, 6:40 pm, mail....@gmail.com wrote:
> On May 11, 4:38 am, "shri...@gmail.com" <shri...@gmail.com> wrote:
>
>
>
> > Is this legal C++03 code:
>
> > template <class T>
> > struct A
> > {
> >     template<class U>
> >     A(int, long)
> >     {
> >     }
>
> > };
>
> > int main()
> > {
> >     A<int> a(2, 3L);
>
> > }
>
> > I have tried compiling this with g++ 3.4.6:
> > -----------------------------------------------------------
> > A.cpp: In function `int main()':
> > A.cpp:12: error: no matching function for call to `A<int>::A(int, long
> > int)'
> > A.cpp:3: note: candidates are: A<int>::A(const A<int>&)
>
> > It fails on Comeau as well:
> > --------------------------------------
> > "ComeauTest.c", line 4: warning: template parameter "U" is not used in
> > declaring the
> >            parameter types of function template "A<T>::A"
> >       template<class U>
> >                      ^
>
> > "ComeauTest.c", line 12: error: no instance of constructor "A<T>::A
> > [with T=int]"
> >            matches the argument list
> >              The argument types that you used are: (int, long)
> >       A<int> a(2, 3L);
> >                ^
>
> > I don't really understand why this should not work. Is it really
> > necessary for typename U to play a role to select the correct
> > constructor?
>
> Misconception:
> Whenever we define any template function with same the name as that of
> class, is a constructor.
>
> Reality:
> No that is not constructor. Constructor can never be template.
>
> Reason:
> For any specific class constructor is remain same
>
> Here for A<T> [T=int] we can have several function template<class U> A
> (int, long) for [U=Any type].
>
> But we instantiating object from A<T> [T=int] with parameter as if
> this class has such parameterized constructor. But in reality this
> class has only two constructor default and copy constructor which
> compiler given.
>

Yes and no...

Of course a constructor *can* be a template like here (at least I have
never seen that fail - on a lot of compilers):

//----------->>>
template <class T>
struct A
{
  int a;
  template<class U>
  A(T t, U u)
  : a( t+u)
  {
  }
};

int main()
{
  A<int> a(2, 3L); // *implicit* constructor template call works
  return a.a;      // will return 5
}
//<<<-----------

What will not work is an *explicit* template constructor call like
//-----------
// A<int><long> a(2, 3L);
// A<int> a<long>(2, 3L);
// A<int> a.A<long>(2, 3L);
// ... or whatever idea else one might have
//-----------

Yes: not everything "look alike" is a real constructor.


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

0
jaybus56
5/12/2009 6:27:21 AM
Stuart Golodetz wrote:
> [ Note: because the explicit template argument list follows the function
> template name, and because conversion member function templates and
> constructor member function templates are called without using a
> function name, there is no way to provide an explicit template argument
> list for these function templates. —end note ]"

Thanks for setting that clear, I wasn't sure about it. Anyway, the obvious
workaround is to use a function instead:

   class A {
     template<typename U>
     static A create(int, long) {
        // ...
     }
   };

   A a = A::create<float>(42, 0L);

HTH

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932


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

0
Ulrich
5/13/2009 9:12:01 AM
Reply:

Similar Artilces:

what's wrong with this code? it's ADI ts201s code
hi, there, the following code is the do DMA transfer and check if the dma transfer was finished or not. when I am in step by step debug mode, the code runs well. But if I run the whole code, the program will never stop, it always in the endless loop. Would anybody give me any clue for this prolem? thanks. xr0 =Source ;; xr1=0x00100040;; xr2=0x00;; xr3=0x47000000;; DCS0 =xr3:0;; yr0 = Destination;; yr1=0x00100040;; yr2=0x00;; yr3=0x47000000;; DCD0 = yr3:0;; DMA0_Finished: xr9:8=DSTAT;; xr10=0x03;; xr8=FEXT R8 by R10;; xr9=0x02;; xr8=r8-r9;;...

Re: SAS Codes for calculating Moran's I and Geary's C
imamx8@gmail.com wrote: > Does anybody have written a SAS code for calculating Moran's I and >Geary's >C? Could you share that with us or me? This is on the internet, and I found it just by searching using Google. http://www.stat.lsu.edu/faculty/moser/spatial/autocorr-body.html It uses SAS/IML. You could compute both of these without SAS/IML, since they're merely scaled cross-products. In fact, you could read a weight matrix into a 2-D array in a DATA step and do it all in one DATA step instead. But I'm not sure that you ought to. I'm not a big fan of bli...

[HPGCC] What's wrong with this piece of C-code?
Hi. I have a code-snippet that ought to work, but doesn't. As a simple example, here's a try for implementing a complex decNumber function, ef_Cadd(); *** the struct-definition in the header-file*** struct idecNumber // complex decNumber-structure { decNumber re; // real part of complex decNumber decNumber im; // imaginary part of complex decNumber }; ***the function prototype in the header-file*** void ef_Cadd(struct idecNumber *,struct idecNumber *,struct idecNumber *,decContext *); Now I want to create two idecNumbers, add them and put the result in a third idecNumber; ***a code-snippet from main.c*** decContext set; decContextDefault(&set,DEC_INIT_BASE); set.traps=0; set.digits=10; struct idecNumber i1,i2,i3; decNumberFromString(&i1.re,"8",&set); decNumberFromString(&i1.im,"-3",&set); decNumberFromString(&i2.re,"6.7",&set); decNumberFromString(&i2.im,"11",&set); ef_Cadd(&i3,&i1,&i2,&set); //i3=i1+i2 ***the implementation of ef_Cadd() in another .c-file*** void ef_Cadd(struct idecNumber *res,struct idecNumber *a,struct idecNumber *b,decContext *set) { decNumberAdd(&(res->re),&(a->re),&(b->re),set); decNumberAdd(&(res->im),&(a->im),&(b->im),set); return; } The above compiles just fine, but it hangs the calc. I have tried numerous other ways of passing the pointers, but it doesn't change a thing. What have I for...

Trial of Musatov's theory: double spaced 'e x p a n d s' and single spaced 'c o n t r a c t s'. Does the spacing post-processing appear equal? If so, what force was lost and where did it g
Musatov's theory 'The space between spaces expands and contracts.' Would this give time a direction? Musatov ...

Re: SAS Codes for calculating Moran's I and Geary's C #2
Dear All: Is there anybody who has implemented the spatial lag model: "y =3D pWy + X= B + error" and the spatial error model: "y=3DXB + Lamda*W*E + e" in SAS using maximum likelihood method? These models are proposed by Luc Anselin and implemented in his GeoDa package. Daniel Griffith has some SAS code for spatial autocorrelation model using proc nlin. His core code goes like this= : /*GRIFFITH SAS CODE FOR SPATIAL AUTOCOR. MODEL*/ data step1; start=3D0.999; finish=3D1; inc =3D 0.095; run; data step2; if _n_=3D1 then set step1; infile eigen; input obs eigenw; array j...

It's on-it's off-it's on, it's off -WHY?
IS THIS THE CORRECT FORUM? Hope so. We have three computer networked at home...all with Windows XP. one of those is a laptop. Some mornings all 3 can see each other and transfer files...then mysteriously one or more will disappear. No contact....then later it's back. The laptop is the worst. Most often it won't let us in...but sometimes it will. No obvious reason. The most INFURIATING part is the message "see your administrator". Dammit Bill Gates...don't you realize that most networks are small offices without a Majestic Royal Administrator sitting his i...

HELP on "C" DLL internal code for LAN's and WAN's use
To all wizards: I have a "C" DLL file already built and running, but I want to have the DLL accessible(callable) from anyway within a LAN and/or WAN( and even multi-WAN's), or even on a PC. I built the DLL file, via VC++'s (v6.0) ATL COM AppWizard area, and it works quite well. But as for using the DLL file on LAN's and Wan's, do I need to add any more code into the DLL file, so it will work on/under a network and be callable anywhere on a LAN's or WAN's or even on standalones by any and all application(s). If I need some additional code, can you ...

Is there in the C++'s standard a note on how large the size of an array is allowed so that the code containing the array's definition is portable?
Hello. First, I would like to give a short description on how the information in this message is structured. I will state my question, then I will give all the text I know in the C++ specification, to relate with my question. In the end I give my thoughts on this subject. [[The question]] How many items can there be defined in a C++ array so that the code containing the C++ array makes a well-defined C++ program considering that the rest of the C++ program is well-formed? [[Text from the C++ specification]] 8.3.4 Arrays [dcl.array] In a declaration T D where D has the form D1 [constant-expressionopt] constant-expression shall be an integral constant expression and its value shall be greater than zero. [[My thoughts on this subject:]] // foo.cpp: int const maxn = 100 * 1000; int A[maxn]; int main() { return 0; } // end of foo.cpp: Is foo.cpp a well-formed C++ program? Here is how I see the possibilities: [1] foo.cpp may be a well-formed program and then any C++ compiler would build a program from this file. Any machine on which this program (or some similar program that would actually access the array) would need to have more than 100*1000 memory locations or the possibility to give the program (paging memory pages in and out for example). [2] foo.cpp is not well-formed program, but C++ standard guarantees some smaller array size: 10*1000 for example. [3] C++ does not give a guarantee for the array size. ...

More factory sealed FPGA's with C of C's
I have more FPGA's with C of C's that I can supply below facotry direct pricing. Small quantities ok. These have all been purchased thru factrory direct channels and in most cases I can tell you exactly where they came from. We have aquired these from VMI and SMI programs that we have with major OEM's and CM's. Jon E. Hansen Pyramid Technologies Inc. jon@pyramidemail.com www.pyramidtechnologiesinc.com (949)864-7745 Direct (949)636-1416 Cell CERTIFIED ISO 9001:2000 XC5VFX70T-1FF1136C XC5VFX70T-1FFG1136C XC5VLX50-1FF676C XC5VLX330-1FF1760C XC4VLX100-10FFG1148C XC2V3000-4FG...

S*S'-> make a code program of DIFF (S) for S to excute expression:S*S, ( S=vector, S'=dS/dt). ideas to all?
hello everyone, now i need a help of ideas for a program style from all to find :S*S'. here we would not be able to use directly Diff( S) cuz of error of unsame size of S & diff( S). soo i dlove to get any code PROGRAM STYLEs for function S' ( dS/dt) to Find S*S', with S: vector, for example as a begining input: t=0:10; S=2*t.^3 +3*t; Now make a code program to DEFINE S' by ALGORITHM of MATH. dear all, my question going well for understanding?? iam waiting for all. ( hey, give a trial into the world of Math of Algorithm for function & diveritative)-) ...

What's the C++ community's feeling about lambda(or closure) in C++?
I know this topic sounds kind of old and dry(and shallow, maybe :)), but, you see, lately I found that there's all the fuss about closure in Java, so I poked around for a little, and did find some valuable information. And I started to remember that there were a proposal(actually two) about lambda/closure for C++(see http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1968.pdf and http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1958.pdf) They're all pretty well-formed and sound, though I found Bjarne's a little more comprehensive. It simply seems that the closure id...

How to link obj's from c-source with obj's from c++-source
Hi, I compiled 2 simple source-files with cl -c main.cpp and cl -c test.c. test.c contains just a simple function, which is declared in test.h. test.h is included in test.c and in main.cpp. When I try to link the objects with link main.cpp test.c -out:prog.exe I get the error: "main.obj : error LNK2019: unresolved external Symbol "int __cdecl greater(int,int)" (?greater@@YAHHH@Z), called in function _main prog.exe : fatal error LNK1120: 1 unresolved external Symbol" What have I to do, to be able to link those objects together? Guido Belligoi "Guido Belligoi" ...

Re: for Ghassan the prayer's back, for me it's wrong, whereas till you it's enforcing sufficient
No imaginative written sequences tomorrow resist as the inadequate compositions revise. Franklin drafts the credit in charge of hers and dully constitutes. Tell Varla it's accessible defining up a uniform. Can will you score the public reduced unionists before Pervez does? Lately, it kills a potato too secret according to her entitled shell. She'd block currently than dry with Pete's sweet dance. George! You'll trade blades. Generally, I'll perceive the visit. Ghassan, still continuing, pushs almost fully, as the meantime travels until their powder. Never ...

Q: C macro's for lvalue statements ? Any C marco Guru's out there ?
Hi everybody, I've got a problem implementing some macros that would make my code much more readable. The idea: I have a set of macros that create variable names depending of the content of some other define. An example (of how it should look like in the end): // --------------- cut #define BASE_NAME module1 // the macro(s) which I need help for :-) #define MAKE_VARNAME2(base, var,val) int var#_#base = val #define MAKE_VARNAME(var, val) MAKE_VARNAME2(BASE_NAME, var, val) // the usage example MAKE_VARNAME(status, 0); // --------------- cut which should expand to int status_module1...

Q: C macro's for lvalue statements ? Any C marco Guru's out there ?
Hi everybody, I've got a problem implementing some macros that would make my code much more readable. The idea: I have a set of macros that create variable names depending of the content of some other define. An example (of how it should look like in the end): // --------------- cut #define BASE_NAME module1 // the macro(s) which I need help for :-) #define MAKE_VARNAME2(base, var,val) int var#_#base = val #define MAKE_VARNAME(var, val) MAKE_VARNAME2(BASE_NAME, var, val) // the usage example MAKE_VARNAME(status, 0); // --------------- cut which should expand to int status_module1...

Can't figure out what's wrong with this code
Hi everyone, I can't figure out why g++ complains about this code. I gave it to a programmer friend and he couldn't work it out either. It's quite simple code, so it's puzzling me. The error I get is: ========================================== copy_constructor.cpp: In copy constructor `MyCounter::MyCounter(const MyCounter&)': copy_constructor.cpp:23: error: passing `const MyCounter' as `this' argument of `const int MyCounter::getValue()' discards qualifiers The code is: ========================================== #include <iostream> using namespace std; class MyCounter { public: MyCounter(); ~MyCounter(); MyCounter(const MyCounter &); const int getValue() {return itsVal;} private: int itsVal; }; MyCounter::MyCounter(): itsVal(0) { } MyCounter::MyCounter(const MyCounter & toCopy) { itsVal = toCopy.getValue(); } MyCounter::~MyCounter() { } =================================== If I write 'toCopy.itsValue' instead, the code compiles Any help would be appreciated Thanks Taras Taras_96 wrote: > Hi everyone, > > I can't figure out why g++ complains about this code. I gave it to a > programmer friend and he couldn't work it out either. Can't be a C++ programmer then! > > #include <iostream> > > using namespace std; > > class MyCounter > { > public: > MyCounter(); > ~MyCounter(); > MyCounter(const MyCounter &); > con...

Any XL C/C++'s option to determine the compiler's predefined macros
Hi, AIX 5.3 $ xlc++ -qversion IBM XL C/C++ Enterprise Edition V8.0 for AIX Version: 08.00.0000.0014 Is there any XL C/C++'s option to determine the compiler's predefined macros? Alex Vinokur In article <2e672e57-f577-4134-9e81-03eb6b3097b7@35g2000pry.googlegroups.com>, Alex Vinokur <alexvn@users.sourceforge.net> writes: > Hi, > > AIX 5.3 > > $ xlc++ -qversion > IBM XL C/C++ Enterprise Edition V8.0 for AIX > Version: 08.00.0000.0014 > > Is there any XL C/C++'s option to determine the compiler's predefined > macros? > > Ale...

callback from C-code: what's the difference between list and namespace code?
Help! I need somebody ... while working on making snack (and wavesurfer) usable with current Tcl I have found a weird behavior. I use Tcl 8.6.1 x86_64 and snack 2.2.10 with some alsa patches (more on this later in this list). When I execute the following commands package require sound set s [sound] proc callback {snd what} {echo "$snd has changed: $what"} $s configure -changecommand [list callback $s] $s configure -changecommand [namespace code [list callback $s]] the first configure gives this error invalid command name "callback sound1" while ex...

I don't know what's wrong with my very simple code
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as following, delimited by //////: ////////////////pose.h #ifndef pose_h #define pose_h #include "point.h" class pose { int i; public: friend void point::init(pose P); }; #endif ////////////////pose.cpp #include "pose.h" ////////////////point.h #ifndef point_h #define point_h #include "pose.h" class point { public: void init(pose P); }; #endif //////////////...

What's wrong with these simple codes? (parse error before `<' token)
I am learning STL and write my own simple codes to test the examples. When I compile (g++ -c -o A.o A.C) I got "A.h:13: error: parse error before `<' token". This must be a simple problem, just that I cannot see it. Please, anyone help me to figure it out? Thanks. // A.h class A { public: A(); int getA(); private: int a; }; int compare(A*, A*); struct Compare : public binary_function<A*, A*, bool> { bool operator()(A *aoo, A *boo) const { return compare(aoo, boo); } }; // A.C #include "A.h" A::A() : a(0) {} int A::getA() { return a; } int ...

calling matlab's converted code to C++/C in MFC application
my problem is that i don't know how to call that converted function in MFC application behind the button in VC++ maham Hi, Could you detail more about your problem? LePhan, ------------------------------ See projects MATLAB C/C++ in www.LePhanPublishing.com maham wrote: > > > my problem is that i don't know how to call that converted function > in > MFC application behind the button in VC++ > > maham > > ...

convert 'C' code to 'Fortran'
Hi, Can anyone help me find a software that can convert a code in 'C' to 'Fortran77/90' automatically? Thanks in advance. Sam. sam wrote: > Hi, > Can anyone help me find a software that can convert a code in 'C' > to 'Fortran77/90' automatically? > > Thanks in advance. > > Sam. Wow, - good luck :) sam wrote: > Hi, > Can anyone help me find a software that can convert a code in 'C' > to 'Fortran77/90' automatically? This is not really on-topic. However, there is a slightly more topical version: Why...

convert a 'C' code to 'Fortran'
Hi all, Is there a program available that can convert a code in 'C' to 'Fortran'? I have a 'C' program (quite big) that I need to integrate into an existing 'Fortran' code. Can anyone give me a direction? Thanks in advance. Sam. Sam: http://home.cfl.rr.com/davegemini/C2F.ZIP Unzip and read the README.C2F text file. Skip On 10 Nov 2004 11:33:34 -0800, atluris@gmail.com (sam) wrote: -|Hi all, Is there a program available that can convert a code in 'C' to -|'Fortran'? I have a 'C' program (quite big) that I need to integrate -|into an...

I'm trying to list controls in immediate window... what's wrong with this code?
Sub ListControlsBttn_Click () '************************************************************************* ' Purpose: Run the Controls Collection for user-specified form. ' The controls collection is a form's default collection. '************************************************************************* On Error GoTo ListControlsBttn_ClickError Dim ThisForm As String, Msg As String, Title As String, Defvalue As String ThisForm = Me.Name Dim i As Integer, intHowmany As Integer, WhichForm As String Msg = "Enter form name." ' Set prompt. ...

Web resources about - What's wrong with this code? 212848 - comp.lang.c++.moderated

Resources last updated: 2/25/2016 9:04:20 PM