daviddoria 334 Posting Virtuoso Featured Poster

Wow, I thought that was a reasonable cast to expect automatically. You're right though, it worked.

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I am trying to get a variable number of arguments in one function, and pass them to another function. I tried this:

#include <iostream>
#include <stdarg.h>

void Function1(unsigned int num, ...);
void Function2(unsigned int num, va_list ap);

int main(int argc, char *argv[])
{
  Function1(3, 1, 2, 3);
  return 0;
}

void Function1(unsigned int num, ...)
{
  va_list ap;

  va_start(ap, num);

  Function2(num, ap);

}

void Function2(unsigned int num, va_list ap)
{
  for (unsigned int i = 0; i < num; i++)
    {
    double val = va_arg(ap,double);
    //printf ("\t%.2f",val);
    std::cout << "Val " << i << " : " << val << std::endl;
    }
    
  va_end(ap);

}

but the output is junk values.

Can anyone see what I've done wrong here?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Awesome! When looking at the output with -v, I found out that the problem was that I had to put:

/usr/lib/gcc/i586-redhat-linux/4.4.1/include/

at the beginning of my CPLUS_INCLUDE_PATH

Seems strange to me that you have to put something form /usr/lib on an INCLUDE path (I was only looking for files inside /usr/include and /usr/local/include) but I guess these files match the version of gcc that is installed or something?

Thanks again,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

When compiling some working code on Fedora 11, I am getting this error:

/usr/include/c++/4.4.1/cstdarg:56: error: ‘::va_list’ has not been declared

I am using:

[doriad@davedesktop VTK]$ g++ --version
g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)

Does anyone know what the problem could be?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Ok I figured out some makedepend stuff and got past that part.

Now I am getting errors like

/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/cstddef:52:11: error: ‘::size_t’ has not been declared
/usr/include/wchar.h:148:40: error: ‘size_t’ has not been declared

Any idea how to fix these?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Unfortunately

sudo yum install libc-devel

tells me

No package libc-devel available.

However, I do have glibc-devel installed (possibly the same thing?), but alas no /usr/include/stddef.h :(

daviddoria 334 Posting Virtuoso Featured Poster

I don't have any packages with libc6 in the name. (I'm on Fedora 11). Why must stddef.h be in /usr/include?

It looks like this makefile is simply calling "make depend" on a bunch of other make files. At the end of the chain, this is what is actually getting run:

depend: 
	makedepend -o$(OBJ) -- $(INCFLAGS) $(MAKEDEPEND_INCFLAGS) $(DEFINEFLAGS) -- $(ALL_FILES)

I tried to add the -I flag by putting this:

MAKEDEPEND_INCFLAGS=-I/usr/include/linux

in the top level makefile, but it still isn't looking in the right place.

Any more suggestions?

daviddoria 334 Posting Virtuoso Featured Poster

Or better yet, it seems like I do have some of these files (stddef.h) on my system, just not in one of the places make depend was looking.

I tried to tell it to look in another place with

make depend -I/usr/include/linux

but it still doesn't seem to be looking there?

daviddoria 334 Posting Virtuoso Featured Poster

'make depend' looks promising.

However, I get a bunch of these:

akedepend: warning:  server.c (reading /usr/include/unistd.h, line 227): cannot find include file "stddef.h"
	not in ../../include/stddef.h
	not in ../../3rd_party/libarg/stddef.h
	not in /usr/X11R6/include/stddef.h
	not in /usr/local/include/stddef.h
	not in ./stddef.h
	not in /usr/include/g++-2/stddef.h
	not in /usr/include/stddef.h

Is there a more "c++" header to use instead of "unistd.h"? I think cstddef has replaced stddef.h, so maybe this is the problem?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

There is no 'configure' file. The readme just says to make sure opengl is installed. There are no autoconf sources. The depend target says:

depend:
cd src; make depend-all

So if I can't regenerate, can I just manually remove those stddef.h kinds of dependencies? It doesn't really make sense to build a header file, does it?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I am trying to compile some software I found online. I am getting a bunch of these errors:

No rule to make target `/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include/stdarg.h', needed by `formCluster.o'.  Stop.

In the Makefiles, there are certainly lines like this:

transform.o: /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/include/stddef.h

The errors seem to go away if I simply remove those lines. Is this a reasonable thing to do (there are zillions of them, so I want to be sure this is the right thing to do before spending a lot of time removing them). I'm assuming it was something to do with old compilers that is not needed anymore?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This seemed to do the trick:

typename list<T>::Iterator loopIter;

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

T is the type that the class is templated on:

template <class T>
daviddoria 334 Posting Virtuoso Featured Poster

Right... so to generate an iterator for a list of T's, you need to use

list<T>::iterator

but that doesn't work...

daviddoria 334 Posting Virtuoso Featured Poster

I am trying to get some code I found online to compile. It looked like this:

#include <iostream>
#include <list>

using std::list;

template <class T>
class leda_list : public std::list<T>
{
private:
  iterator loopIter;

the error was: ‘iterator’ does not name a type

I tried changing it to:

list<T>::iterator loopIter;

but it says "ISO C++ forbids declaration of ‘iterator’ with no type".

Any thoughts on what could be the problem?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

A bit of background - I am trying to get an existing script to run. I tried to replace this line:

>>> from wxPython.glcanvas import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/__init__.py", line 15, in <module>
    import _wx
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/_wx.py", line 3, in <module>
    from _core import *
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/_core.py", line 15, in <module>
    import wx._core
ImportError: No module named _core

with this:

>>> from wx.glcanvas import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named glcanvas

and it looks like wx doesn't have a glcanvas.

Is wx not going to be very backwards compatible with wxPython?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

If I

sudo yum remove wxGTK

it tries to remove wxPython as well. Is there a way to remove it without removing wxPython?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I see that deprecation warning, but then it doesn't work.

[doriad@davedesktop gecko]$ python
Python 2.6 (r26:66714, Jul  4 2009, 17:37:22) 
[GCC 4.4.0 20090506 (Red Hat 4.4.0-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from wxPython.wx import *
__main__:1: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained.  Please switch to the wx package as soon as possible.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/__init__.py", line 15, in <module>
    import _wx
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/_wx.py", line 3, in <module>
    from _core import *
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/_core.py", line 15, in <module>
    import wx._core
ImportError: No module named _core

However, import wx seems to work fine. Should I just use that instead?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

_core.py indeed exists there. I just installed wxPython this morning (sudo yum install wxPython*) so I don't think reinstalling would change anything. Any other thoughts?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I am trying to use wxPython (the version that ships with Fedora 11 - I'm not building it from source). I am seeing:

from wxPython.wx import *
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/__init__.py", line 15, in <module>
    import _wx
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/_wx.py", line 3, in <module>
    from _core import *
  File "/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython/_core.py", line 15, in <module>
    import wx._core
ImportError: No module named _core

I tried adding:

export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wxPython:/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx:/usr/lib/python2.6/site-packages/wx-2.8-gtk2-unicode

to my path in .bashrc, but it didn't change anything.

Any suggestions?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I want to make a type to differentiate degrees and radians. I wanted something like this to produce a compiler error:

#include <iostream>

typedef double Degree;
typedef double Radian;

void MyFunction(Radian angle);

int main()
{
  Degree foo = 3.0;
  
  return 0;
}

void MyFunction(Radian angle)
{
  std::cout << "Success." << std::endl; 
}

But the typedef just translates directly to "double" so there is no problem passing a Degree to a function expecting a Radian.

I could make a struct and do

Radian foo;
foo.value = 3;
MyFunction(foo);
...
void MyFunction(Radian r);

But then I always have this ".value" hanging around everywhere. Is there no way to do what I'm looking to do?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This was just a goof on my part, but it was quite annoying and maybe it could be handled a bit better. I was on a different machine than normal, so I was not logged into daniweb but I didn't realize it. I found an interesting post and spent quite a while writing a reply. When I clicked "post a quick reply" it told me that I was not logged in (correctly). When I clicked "back", my reply was gone (the text box was empty). Is there a way to have the text remain in the box in a case like this?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Some libraries that you may find helpful:

ITK:
http://itk.org/

VIL (part of VXL):
http://vxl.sourceforge.net/

OpenCV:
http://opencv.willowgarage.com/wiki/

CImg
http://cimg.sourceforge.net/

Hope that helps.
Dave

Salem commented: Nice +19
daviddoria 334 Posting Virtuoso Featured Poster

If I go to:

view -> arrange by -> current view -> customize current view -> other settings

I can change the "row font" size for the current folder. If I have 100 folders and I want to change the font size for the messages in all of them, you can see how this would get obnoxious. Is there a way to change the "global default row font size"?

Thanks,

David

daviddoria 334 Posting Virtuoso Featured Poster

Sorry, this was a typo - should be: double color[3] = {1,2,3}; // ... assign ptr .... meant do something like ptr = GetAValidPointer() The part I was concerned with is the following. I was just trying to set the stage (which I apparently did worse than poorly!):

*ptr = *color++;
ptr++;
daviddoria 334 Posting Virtuoso Featured Poster

Why people write such cryptic code I will never understand...

Can someone explain what is going on in the following:

double color = {1,2,3};

double *ptr;
// ... assign ptr ....

*ptr = *color++;
ptr++;

So this line *ptr = *color++; sets the value of the first location of the ptr array to the first location of the color array, and then increments the color array? So the next time *ptr =*color is called, *color will now be 2 instead of 1? Is this correct?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Very cool - thanks!

daviddoria 334 Posting Virtuoso Featured Poster

Is there a way to see what a macro gets expanded to?

I tried to put it in quotes and use printf, but of course printf just printed exactly the string.

The result of:

#define SetMacro(name,type) \
virtual void Set##name (type _arg)

int main()
{
  printf("SetMacro(Test, int)");
}

is SetMacro(Test,int) .

What I want to see is: virtual void SetTest(int _arg) .

Is this possible?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I removed the <br>'s: http://www.rpi.edu/~doriad/Personal.html

but the space was still huge. I then changed margin-bottom from 30px to 10px in the .css file and all is well :)

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

almost bob - thanks! You are right, it was tough to see the missing <tr> until the text was removed.

I'd like to try the "non-80's" method. I'm using a style sheet so my header currently looks like

<head>
<title>David Doria - Technical Reports</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

I tried simply adding the <style> section you recommended:

<head>
<title>David Doria - Technical Reports</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<style type='text/css'>
img {margin:10px; float:left; width:230px;height:190px}
</style>
</head>
<body>

but the result is no good. I'm sure it's clashing with the way I am calling the css file? (Please bear with me, I'm clearly not a web programmer :) but I should be able to get this one-time thing with another little bump from you!)

Was this <style> supposed to be added to the css file itself?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

A friend of mine has a big table on his website:
http://www.rpi.edu/~chens/Research.html

I think it looks great, so I tried to copy this style/code, but it is making too many columns:
http://www.rpi.edu/~doriad/TechnicalReports.html

I read http://www.w3.org/TR/html4/struct/tables.html , but it looks to me like I have done everything right (all it is are <tr> and <td> tags).

Can anyone spot the bug?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I have some sections like:

<h3>EngineeringNotes.net</h3>
<br>I have never ....

(see this page: http://www.rpi.edu/~doriad/Personal.html)

Why is there such an enormous space between the header and the text? I thought <br> should just insert a single line break?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I ended up having to create a LawyerClass object and then copying in the data from the PersonClass. Thanks for the discussion/help!

daviddoria 334 Posting Virtuoso Featured Poster

Consider two classes, PersonClass and LawyerClass.

If LawyerClass derives from PersonClass, you can create a PersonClass* as a LawyerClass, like

PersonClass* Person = new LawyerClass;

then you can convert it to a LawyerClass* with

LawyerClass* Lawyer = static_cast<LawyerClass*>(Person);

However, if you don't know that the person should be a lawyer to start with:

PersonClass* Person = new PersonClass;

is there any hope of transforming him into a lawyer? This:

LawyerClass* Lawyer = static_cast<LawyerClass*>(Person);

does not work - Lawyer is invalid after the cast.

The reason I need to do this is that there is a library I am using that has a reader class, say ImageReader that returns an Image. Then I have created a subclass called FancyImage and I want to convert the output from the reader (Image) to my FancyImage but I cannot control what the reader outputs.

Any thoughts?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Say you have a class that has members

private:
double a,b,c,d,e,f,g,h,i;

You can make an accessor like:

double operator[](int index)
  {
    if(index == 0)
      return a;
    else if(index == 1)
      return b;
    else if(index == 2)
      return c;
  }

But how would you do something like this:

double operator[][](int rindex, int cindex)
  {
    if(rindex == 0 && cindex == 0)
      return a;
    else if(rindex == 1 && cindex == 0)
      return b;
    else if(rindex == 2 && cindex == 0)
      return c;
    else if(rindex == 0 && cindex == 1)
     return d;
..... etc ...
  }

The compiler doesn't like the above attempt. The behavior I'm looking for is:

MatrixClass Matrix;
// ... fill it
double test = Matrix[0][1];

Thoughts?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Jas, but won't it still crash evaluating the second part of the conditional?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

If I have the following setup:

Point* MyPoint = Object->GetMyPoint();

if(MyPoint->GetValue() != 2)
  do something;
else
  do something else;

If MyPoint is NULL or invalid, the MyPoint->GetValue() will cause a segfault.

This should fix it:

Point* MyPoint = Object->GetMyPoint();
if(MyPoint)
{
  if(MyPoint->GetValue() != 2)
    do A;
  else
    do B;
}
else
  do B;

But that is quite awkward, as it makes me repeat B and it adds an extra nested layer.

Is there a better way to do this?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

From that algorithm you gave I don't understand how you are supposed to get more than one factor?

Maybe this will be a good starting point for you - it just gets the smallest factor (besides 1) and multiplies it by successive integers until it gets to the "right" number (where P * mult = I).

#include <iostream>

int main()
{
  //an example input
  int I = 40;
  
  //find the smallest P that divides I evenly
  int P = 2;

  while(I % P != 0)
  {
    P++;
  }

  //output the smallest P that was found
  std::cout << P << std::endl;

  //show what P multiplied by everything up until the correct amount
  int mult = 1;
  while(mult * P <= I)
  {
    std::cout << mult << " * " << P << " = " << mult*P <<std::endl;
    mult++;
  }

  return 0;
}

Good luck.
Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is this what you are looking for?

#include <iostream>
#include <string>

int main()
{
  const char NONWORD[] = "\n";
    
  std::string test = NONWORD;
  return 0;
}
daviddoria 334 Posting Virtuoso Featured Poster

Here you have declared the variables, but then output just constant expressions...

I'd suggest googling for "basic c++" and trying some of the simple examples you find until you get familiar with the basics. Then you can try to write this triangle program as a demonstration to yourself that you've learned something!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand why you would want to remove stl features? They make things MUCH easier...

daviddoria 334 Posting Virtuoso Featured Poster

You need to give us more of a feeling that you have really tried. Did your code produce errors? Or incorrect results? Why don't you try some simple cases like the number '4'. You should expect to see factors of 2 and 2, right? Small examples like these will help you debug the code, then you can try large numbers.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

First of all, you should #include <iostream> instead of #include <iostream.h> . This is the "new" c++ way to do it.

Second, you have to #include <cstring> to use strcpy.

Third, you have not declared getHours in the header file. To show you this, the compiler says: "error: no 'int Person::getHours()' member function declared in class 'Person'".

Fix these things and let us know if you have any more problems.

David

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand the problem...

int NumberOfPositiveRoots(root1, root2)
{
int counter = 0;
 if (root1 >= 0)
{
counter++;
}
if (root2 >= 0)
counter++;
}
return counter;
}
daviddoria 334 Posting Virtuoso Featured Poster

What you have there is simply a hard coded triangle. You need to write the code to setup the triangle's height and width. Give it a shot and post your problem once you try it.

daviddoria 334 Posting Virtuoso Featured Poster

Please explain exactly what you need. What operating system are you using?

daviddoria 334 Posting Virtuoso Featured Poster

Is there a "correct" way to draw a line betwee the header and body of a document in word 2007? I've been using a Shapes->Lines line, but it seems silly because there is no way to center it, etc.

Any ideas?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I had to instantiate the constructor by adding this to the instances.inc file:

template Graph<int,int,int>::Graph(int, int, void (*)(char *));

Does anyone understand why / know if the compiler can be told to do this automatically? I thought the whole point of templates was so you did NOT have to know the types that would be used?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

With this code:
http://www.rpi.edu/~doriad/Daniweb/maxflow/
If I run

g++ Example.cpp graph.cpp

with g++ 3.3, everything works fine. However if I run the same command with g++ 4.4, I get this error:

Example.cpp:(.text+0x38): undefined reference to `Graph<int, int, int>::Graph(int, int, void (*)(char*))'

Does anyone know how I can get this to work with g++ 4.4?

Thanks!

David

daviddoria 334 Posting Virtuoso Featured Poster

caperjack - that removes the big calendar button, but it doesn't remove calendar from the "Favorite Folders" list.