What's wrong with this code? 212848

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply shri314 5/10/2009 4:38:03 PM

See related articles to this posting


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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply 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
Reply Ulrich 5/13/2009 9:12:01 AM
comp.lang.c++.moderated 10665 articles. 10 followers. Post

8 Replies
186 Views

Similar Articles

[PageSpeed] 5


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

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 &qu...

Browser crashes with below code.What is wrong in below code.
Hi, All my browser are either hanging or crashing due to below code,Any ideas a= s what is happening.While debugging my jsp page, I narrowed down to below c= lone method of jquery.Also as per my understanding there are some tags in H= TML5 which do not require to have end tags, does UL require end tag as per = HTML5 ?. Again I am no expert in Javascript but again trying to get my hands dirty e= ither by reading books or trying on my own by googling here and there on ne= t. <!DOCTYPE HTML> <html> <head> <meta charset=3D"utf-8"> <title>Simple Test Case&l...

Is my code wrong?
I am now being mad now! I want to clear up my /home directory, to delete all subdir but the 'yb' dir and then copy the /usr/portage to here. so I do following: cd /home find ./ -maxdepth 1 ! -name yb -exec rm -fr {} \; ; cp -fr /usr/portage/ ./ but it delete all in /home, all my valuable data! God, what is wrong! Bo Yang wrote: > I am now being mad now! > I want to clear up my /home directory, to delete > all subdir but the 'yb' dir and then copy the > /usr/portage to here. > > so I do following: > > cd /home > find ./ -maxdepth 1 ! -name yb -e...

What am I doing wrong with this code?
I think I'm having a brain fart. Seriously... Plot[{1/(1 + y^2), (1/y - 1)^(1/2)}, {y, 0, 5}] What is wrong with that code? Maybe it's not solvable in mathematica? I'm trying to plot nullclines of a system of ODEs. and those function up there are them. I just can't get mathematica to plot them in the same graph. I get an error message saying... >From In[22]:= (1/y - 1)^(1/2) is not a machine-size real number at y = 1.0000001666666667`. Any help is appreciated. sean Try this: Show[{Plot[{1/(1 + y^2)}, {y, 0, 5}], Plot[(1/y - 1)^(1/2), {y, ...

what is wrong with my code
string args= "srcipt arg1 arg2 arg3..." ..... int size=args.size()*2; // to make sure I have enough room char *argvec=new char[size]; memset(argvec,'\0',size); args.copy(argvec,size); pid_t pid; if(pid=fork()<0) { cerr<<"failed in fork(), exit 1\n"; exit(1); } else if(pid==0) { if(execv("/home/work/bin/script",&argvec)<0) { cerr<<"failed in execv, exit 1\n"...

What is wrong with this code?
Hello, I am wondering whats wrong with the following code. It is crashing on Linux, but works fine on AIX. The function basically get DbNm@Srvr string and then return DbNm and Srvr back to the calling program. #define IDFR_VAL_SIZE 100 int rmlPvtGetDbNm(char *sDb, char *sSrvr, char *sDbNm) { char *sTok; memset(sDb, '\0', IDFR_VAL_SIZE); memset(sSrvr, '\0', IDFR_VAL_SIZE); sTok = malloc(IDFR_VAL_SIZE); sTok = strtok( sDbNm, "@" ); strcpy(sDb, sTok); sTok = strtok(NULL, "@" ); strcpy(sSrvr, sTok); free(sTok); ...

To Code or Not to Code?
Just read a paper with the very interesting title, "To code or not to code: lossy source-channel communication revisited", Gastpar et al, IEEE Trans Information Theory, May 2003, p 1147. It's available for free here... http://www.eecs.berkeley.edu/~gastpar/01197846.pdf As far as I can tell, the idea is that although source and channel coding can be separated without loss of optimality (Shannon) it can be overly complex, and less complex systems can get close to this opimality by combining source and channel coding, or at least matching them in some way. This sounds like a pret...

wrong code?
When I run the following code I get the error "??? Error: File: C:\matlabR12\work\opti.m Line: 17 Column: 8 "identifier" expected, "(" found." I really don't know what the problem can be. Can anyone give some help? u0=326e-4; coX=8.2e-3; l1=180e-9; l2=180e-9; l3=180e-9; l4=180e-9; l4=180e-9; vtb=510e-3; vt=500e-3; iref=1.3e-3; ir=iref; vb=0.95; r=50; obj = @(X) (-i1+0.5*u0*cox*X(2)/l1*(X(1)-vt)^2)^2 + (0.5*u0*cox*X(3)/l2*(X(4)-vtb)^2-i2)^2 + (0.5*u0*cox*X(5)/l3*(X(6)-vt)^2-i3)^2 + (0.5*u0*cox*X(7)/l4*(X(8)-vtb)^2-i4)^2 + (u0*cox*X(9)/l5*(X(10)-vtb)*...

what is wrong about this code
I have found this code for peak detection on the file exchange. function [p,t]=peaks(s) warning off ds=diff(s); ds=[ds(1);ds];%pad diff filter=find(ds(2:end)==0)+1;%%find zeros ds(filter)=ds(filter-1);%%replace zeros ds=sign(ds); ds=diff(ds); t=find(ds>0); p=find(ds<0) I want it to find peaks of an arabic word then I have created vertical projection for the word and apply this code, unfortunately, this error message appeared: ??? Error using ==> vertcat CAT arguments dimensions are not consistent. why the author made this concatenation?what is the wrong? Error...

what wrong with my code ?
Hi, how can I remove the last 4 characters. this code doesn't work. thanks. data datasetlist_new; set datasetlist; if upcase(x) = "TEMP" then y = substr(Name,1,length(Name)-4); run; ...

Coding to the ][, Coding to the ///?
Now that I've gotten some very limited /// stuff running (thanks to MESS)...I've been thinking of trying to code to the ///. Fortunately, getting software to the emulated /// is a snap. I'd just use the same strategy as I use for the ][, using the emulated ][+ from ApplePC. Save to a ProDOS disk, boot on the ///. The questions become a bit more complex here. 1. I assume the 40x24 text mode works similarly to the ][. Running on MESS, part of the text screen would periodically get "colorized", and I suspect the color memory is stored on text page 2. This woul...

what is wrong with this code?
I'm trying to make a simple stack based postfix calculator, but I have this error where I somehow apply #f to whatever I provide to the reader. I could someone point out whatever it is? ;(sorry about the formatting, but google messes it up) (define (mult a b) (* a b)) (define (add a b) (+ a b)) (define (div a b) (/ a b)) (define (sub a b) (- a b)) (define rpn-repl (let ((stack '())) (letrec ((rpn-eval (lambda (args) ((null? args) '()) (if (list? args) (cond ...

What is wrong with this code?
Hi everyone: Could someone look into what could possibly be wrong in these lines of code? It looks all good to me but for some reason the combo box that is created, is not shown with all the properties (attributes) set. Actually the message box (alert) that is used to review the content of the SELECT statement, shows that the only attributes set are size = 1 and id = theComboBox. The other two statements, refering to name and style, are completely ignored, actually never placed as attributes of the SELECT node. As a result the combo is shown with a defaulted font size different than the rest o...

What is wrong with this code?
Hi all, I am trying to get an understanding of classes within PHP. What is wrong with this code: <html> <title> This is my test for creating a class </test> <body> <?php class Test { $Message = "Default Message"; Test($Message) { $this->$Message=$Message; } Display_Message() { echo "$Message"; } } $TestObject = new Test("Hello World!!"); $Testobject->Display_Message(); ?> </body> </html> Thanks in advance for your help. siu02rk wrote: > Hi all, > > I am...

What is wrong with my code??
I am writing code to get a subset of table records, but it is not looping properly through the fields, it keeps getting stuck in some sort of infinite loop and I have to be able to walk the whole recordset. Am I not using the do loop properly?? dim db as DAO.database dim rs3 as DAO.recordset dim strSQL as string strSQL = "SELECT tblComments.AuditID, tblComments.txtTopic, tblComments.memAuditTopicComments" strSQL = strSQL & " FROM tblComments" strSQL = strSQL & " WHERE tblComments.AuditID=" & lngAuditID Set rs3 = db.OpenRecordset(strSQL) rs3.MoveFirst...

What is wrong with my code
Hi folks, I write two srcipts to check files in a given directory. Version 1 uses regular expression and works but I cann't find the size for each file. Version 2 uses Ruby built-in File.file? method but it doesn't work at all. I wonder what is going on with my scripts? Thank you, Li #######Version 1: path='c:\path\to\folder' Dir.open(path).each do |file| if file=~/(\w+|d+).(\d{3,})/ puts file puts File.size(file)# this line doesn't work file_number+=1 end end puts puts 'Files',path puts ...

Code is Wrong?
What in this code is stopping me from adding new records? Private Sub ListProd_Click() On Error GoTo GotError DoCmd.GoToControl "[Sales Details]" Me![Sales Details].Form.AllowAdditions = True DoCmd.GoToRecord , , acNewRec Me![Sales Details]![ProductID] = Me.ListProd.Column(0) Me![Sales Details].Form.Dirty = False Me![Sales Details].Form.AllowAdditions = True 'DoCmd.OpenForm ("Modifiers") ExitSub: Exit Sub GotError: Select Case Err.Number Case 2501 Resume ExitSub Case Else MsgBox Err.Number ...

What is wrong in this code ?
hai i am not able to overload a member function of base class in derived calss.what is the wrong thning i am doing here in the following program. # include<iostream> using namespace std; class Quad { public: void Area() ; void Desc() ; }; class Square : public Quad { public: using Quad:Area; void Area(int x) { cout<<"Area of square is = "<<x*x<<endl; } void Desc() { cout<<"This Derived class Square from Base Class Quad"<<endl; } }; class Rectangle : public Quad { public: using Quad:Area; void Area(i...

What is wrong with this code?
Hi, The code in question is- function test options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]); [T,Y] = ode15s(@vdp1000,[0 20]),[1 1 1 1 1 1 120 36e3 1 1 10 110 300 300 12 35e6]) plot(T,Y(:,11),'-',T,Y(:,12)),'-.',T,Y(:,13),'.',T,Y(:,14),'.-',T,Y(:,15),'*',T,Y(:,12)),'+') function dy = vdp1000(t,y) dy=zeros(16,1); y(1)=1; y(2)=1; y(3)=1; y(4)=1; y(5)=1; y(6)=1; y(7)=120; y(8)=36e3; y(9)=1; y(10)=1; y(7)=y(11)+y(12); y(8)=y(11)*y(13)+y(12)*y(14); y(15)= y(9)*y(11)*y(13)/(y(1)-y(11)); y(16)= y(9)*y(12)...

what is wrong with code?
what is wrong with code? why its not working? I=imread('eight.tif'); subplot(1,3,1); imshow(I); title('original image'); J=imnoise(I,'salt & pepper',0.10); subplot(1,3,2); imshow(J); title('noisy image'); D=double(J); [x,y]=size(D); xx=x+2; yy=y+2; med(3)=0; n=zeros(3); n1=zeros(xx,yy); %n1(2:x+1,2:y+1) =D for i=2:xx-1; for j=2:yy-1; if(0>D(i,j)<255) for k=i:i+2; for l=j:j+2; n(k,l)=D(k,l); end end O=median(n); n1(i,j)=O(1); end end end A=uint8(n1); subplot(1,3,3); ...

What is wrong in this code ... ???
Hello , Well Im new to programming in Ruby Language ( Infact only an hour back i started it ) . class Student def initialize(name) @name = name end def show s = "Name : " + name return s end end st = Student.new("Abc") ; st.inspect I have Windows Xp Sp2 n when i run this program on console , it doesn't show me anything . There is no error but it is also not shwoing me anything . st.inspect should show info st.to_s also doesn't show anything if i write st.show it also doesn't work . I wuld be thankful if u people help me out Thanks in adva...

what wrong in this code
here is a code snippet which is a part of larger program . GCC shows error as invalid lvalue in assignment as i have marked in the code. char* replace_escape_sq(char * text_in){ int c; char * text=text_in; for(text; *text; text++){ c=*text; if(*text=='&'){ //find the escape char and do the replacement //&lt --------- < if(*text+1=='l' && *text+2=='t' && *text+3=';'){ text+=3; /* ERROR */ c='>'; } ...

What is wrong with this code?
Sorry I hit enter on the other post I'm trying to add todays date to my created sql string #!/usr/bin/ksh # This script reads flatfile converts data to sql and loads records into Oracle DB # Need to insert todays date into database thefile="testcut.txt" dt=`date +'%Y%m%d'` awk '{print "insert into db(date,f1,f2,f3,f4,f5) values (" "\""$dt"\",", "\""$1"\"\,", "\""$2"\"\,", ...

What is wrong in this code?
<?php $string = "Copia (3) di Copia (99) di unita"; $val = "Copia (99) di unita"; if (eregi("Copia \(+[0-9]+\) di ".$val,$string)) { $vara = explode("Copia (",$string); $vara = explode(")",$vara[1]); var_dump($vara); $maxim = $vara[0]; } else $maxim = 0; ?> I always get $maxim = 0, so eregi is evaluated as false even if is "Copia (number) di " in string. It works this way: <?php $string = "Copia (3) di unita"; $val = "Copia (3) di unita"; if (eregi("Copia \(+[0-9]+\) di ".$val,$stri...

what is wrong with this code?
f[x_] := If[EvenQ[IntegerPart[x]], 0.4, 0.8]; Plot[f[x], {x, 1, 101}] You're just seeing some artifacts. Increasing the plotpoints gives a better looking plot: f[x_] := If[EvenQ[IntegerPart[x]], 0.4, 0.8]; Plot[f[x], {x, 1, 101}, PlotRange -> {0, 1}, PlotPoints -> 69] BTW, next time try to be a bit more descriptive than just "what's wrong with this", OK? Am 02.04.2013 09:24, schrieb dougwangsaif@gmail.com: > f[x_] := If[EvenQ[IntegerPart[x]], 0.4, 0.8]; > Plot[f[x], {x, 1, 101}] > nothing wrong and this is correct too: f[x_] := If[Ev...