daviddoria 334 Posting Virtuoso Featured Poster

I really recommend you try to narrow the problem down to a ~ 15 line demonstration of the problem that we can look at. You should use a debugger to step through the code until you reach the line that it is crashing on - code after that is certainly irrelevant. And I'd bet much of the code before that could be removed without disrupting the problem.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You were on the right track by including sstream, but then you didn't use it!

Long lists of code like this this:

if (IPd == ip0) {
			k = 0;
			f0.open ("Node0.txt"); 
			f0 << "I received a packet from Node " << i << "\n"; // write all the packets that node0 recived and from where
		}
		else if (IPd == ip1) { 
			k = 1;
			f1.open ("Node1.txt");
			f1 << "I received a packet from Node " << i << "\n";
		}

is almost always a bad idea.

Assume IP is an int (0, 1, ... 15). You can replace about 100 lines with simply:

stringstream ssFileName;
ssFileName << "Node" << IP << ".txt";

f0.open (ssFileName.str()); 
f0 << "I received a packet from Node " << IP << "\n";

Hope that helps,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

There are literally hundreds of tutorials about pointers online. I'd recommend reading as many as you can and asking here if you have specific questions.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You should reply to the thread with the solution, instead of removing the question. If you delete the question, the answer doesn't help anyone in the future!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Since this is a c++ forum, I'll give a c++ example (I don't know anything about that extern c stuff!)
main.cpp

#include "test.h"

int main()
{
  Test a;
  a.foo();

  return 0;
}

test.h

#ifndef test_h
#define test_h

#include <iostream>

class Test
{
  public:
    void foo();
};

#endif

test.cpp

#include "test.h"

void Test::foo()
{
  std::cout << "working" << std::endl;
}
g++ -c test.cpp -o test.o
g++ main.cpp test.o -o main

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd recommending changing the title of your post. This isn't really that easy of a question (at least to me, haha). You should call it "Detecting splits in a btree"

Dave

Ancient Dragon commented: Agree. Not an easy question to me either. +28
daviddoria 334 Posting Virtuoso Featured Poster

I don't understand, if you know c++, this shouldn't be an issue at all... you pretty much just need to add some braces.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

My main comment is that I would definitely use STL vectors instead of all of your arrays - the memory is managed automatically, you can do bounds checking if you wish (with .at() ), you do not need to know/guess the size ahead of time, you can resize them, and the list goes on.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

My suggestion is to not use OpenGL directly, but rather, use VTK! (http://vtk.org/)

I have been working hard for the last year writing examples, which you can find here: http://www.vtk.org/Wiki/VTK/Examples

There is certainly a learning curve (but there is with OpenGL, too, as you're experiencing), but it's much cleaner than OpenGL once you get the hang of it.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to the forum. You need to close your code tag with '/code', instead of 'icode' for it to display properly.

I recommend you do the following: Make as simple as an example as you can. Do not take input, but rather hard code some values. Make a 10 line example that tries to sort some values, that should get you started. Report back here when you have a < 20 line compilable example that you are stuck with a specific problem, you will definitely get much more help that way.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You could input a string instead of an int and then check if the string contains a '.'.

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

A sample program? Or do your homework for you?

daviddoria 334 Posting Virtuoso Featured Poster

Ah, I guess I have to use a deque if I want an iterator.

daviddoria 334 Posting Virtuoso Featured Poster

Hmm am I doing something wrong? I am getting this error:

error: 'iterator' is not a member of 'std::queue<int, std::deque<int, std::allocator<int> > >'

Here is the code:

#include <iostream>
#include <queue>
#include <cstdlib>
#include <algorithm>

int main(int argc, char* argv[])
{
  std::queue <int> q;

  q.push(1);
  q.push(2);
  q.push(3);
  
  std::queue<int>::iterator pos = std::find( q.begin(), q.end(), 2);
  if ( pos == q.end())
    {
    std::cout << " not found" << endl;
    }
  else
    {
    std::cout << " not found" << endl;
    }
 
  return 0;
}

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Ah, great. I didn't see any functions to access elements of a queue other than the front and back, but I guess find from 'algorithm' can do exactly what I was looking for. Thanks a lot!

daviddoria 334 Posting Virtuoso Featured Poster

mattjbond,

Thanks for the reply. That is a almost what I'm looking for, except it shouldn't only not allow duplicate elements adjacent to each other, duplicate elements should not be allowed at ANY position in the queue.

void push( const T& elem ) 
   { 
      
      if ( elem is already somewhere in the queue)
         return;
      c.push_back(elem); 
   }

This is the part that I didn't know how to do with a queue (without popping through the whole queue and then recreating it, which seems insanely inefficient).

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is there a data structure that lets me push and pop things onto/off of a queue, but also doesn't allow duplicates?

E.g.
I want

queue a;
a.push(1);
a.push(2);
a.push(2);
a.push(3);

to only have 3 elements, because 2 was added twice so the second time it is just ignored.

Any ideas?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

Did you download and install VTK?

http://vtk.org/VTK/resources/software.html#latest

daviddoria 334 Posting Virtuoso Featured Poster

I'd recommend using an std::vector to store you students. You'd want to use a set of if/else if statements or a switch statement to map the numerical grades to letter grades.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Your code compiles fine on my machine.

g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is this c++? I don't think ref class CSquare: Rectangle or property int lt are valid c++ statements.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

If you're on Windows, you'll want this:
InsightToolkit-3.16.0.zip (hosted at SourceForge)

You still haven't explained what you want to do - if you want to DISPLAY the image, you'll want to use VTK instead of ITK.

http://vtk.org/

Then here is how you would use it:

http://www.vtk.org/Wiki/VTK/Examples/BackgroundImage

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What do you need to do with them? For image processing, I use ITK (http://itk.org/) or VIL (part of VXL : http://vxl.sourceforge.net/).

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Can you post a compilable snippet? I.e. you're Event class is missing.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

There are plenty of tutorials on the 'this pointer'. The short version is yes,

std::ifstream lookup( this->name.c_str() );

is what it should look like. The "this->" doesn't actually change anything (in this case), it just lets the reader know that "name" is a member variable of the class the function we are in belongs to.

I suggest you make the smallest compilable bit of code that produces the errors you're seeing. That will help you isolate the problem. If you still can't figure it out, it will help us debug it much easier for you.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I suggest making the smallest compilable code that demonstrates your problem (< 15 lines). It will help you narrow down where the problem is, and if you still can't figure it out, it will save us massive time helping you debug it.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You did not post clear.h as far as I can tell.

I STRONGLY encourage you to use the "this" pointer explicitly. e.g.
in data::lookup() - std::ifstream lookup( this->name ); instead of std::ifstream lookup( name ); It makes code much more readable.

Also, you'll get a bunch of errors because the ifstream constructor doesn't accept an std::string, you have to use

std::string a = "test";
std::ifstream lookup( a.c_str());

instead of

std::string a = "test";
std::ifstream lookup( a);

Hope that helps get you a bit farther.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I recommend posting this question here:

http://tech.groups.yahoo.com/group/OpenCV/

daviddoria 334 Posting Virtuoso Featured Poster
int strSize = word_to_guess.size();
daviddoria 334 Posting Virtuoso Featured Poster

I don't see main anywhere - can you post everything so we can try to compile it?

daviddoria 334 Posting Virtuoso Featured Poster

I suggest you start by stripping the code down to the smallest portion that compiles successfully and add code line by line until it breaks. That should give you some hints about where the problems are.

daviddoria 334 Posting Virtuoso Featured Poster

Ah, yes. In mathematics the standard is +x is 0 degrees and the angle increases counter-clockwise. You'll have to adjust accordingly.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd agree with the second sentence. I wouldn't say anything about allocating memory.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Those are linker errors. You need to go into your project settings and make sure you are linking to COMCTL32.LIB and USER32.LIB.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

In the constructor, you would probably want to set all of the coefficients to 0. The idea is just that you really NEVER want to have unassigned variables. What if you forgot they were assigned in the read function and tried to access them before that? You would end up with a junk value.

Dave

gnarlyskim commented: very clear in explanations +1
daviddoria 334 Posting Virtuoso Featured Poster

I'd really recommend getting the problem down to a <20 line example that we can look at.

Dave

daviddoria 334 Posting Virtuoso Featured Poster
#include <cmath>
#include <iostream>

int main()
{
  double x1 = 0;
  double y1 = 0;
  double x2 = 100;
  double y2 = 100;
  
  std::cout << 180./3.14159 * atan((x2-x1)/(y2-y1)) << std::endl;
  
  return 0;
}

The answer is 45 not 315 going from (0,0), to (100,100), right?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

almostbob,

The link I posted was my code. Here it is directly on the forum:

index.html

<html>
<head>
<link href="table.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>

<table>
        <!--headers-->
        <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        </tr>

        <!--First row-->
        <tr>
        <td>Peter</td>
        <td>Griffin</td>
        </tr>

        <!--Second row-->
        <tr>
        <td>Lois</td>
        <td>Griffin</td>
        </tr>
</table>

</body>
</html>

table.css

/* th = table header, td = table data */

table
{
width:100%;
}

th
{
height:50px;
text-align:center;
}

td
{
height:50px;
text-align:center;
}

~Dave

daviddoria 334 Posting Virtuoso Featured Poster

After reading a few tutorials, it looks like this:
http://www.rpi.edu/~doriad/Examples/Table/

should make a full (100%) width table. However, the width is actually very small and the table is on the left of the page.

Does anyone see what is wrong here?

Thanks,
Dave

daviddoria 334 Posting Virtuoso Featured Poster

ah, I thought the struct was called 'ma' and the instance of it was called 'mx', that's why I had recommended using just

void func(ma mx)
daviddoria 334 Posting Virtuoso Featured Poster

I'm still confused. That is line #1 of the very first post in the thread, and I'm still not sure which space you're talking about.

daviddoria 334 Posting Virtuoso Featured Poster

Which space? Line 1 is just an include, right?

daviddoria 334 Posting Virtuoso Featured Poster

AncientDragon, I don't get this syntax:

void func(struct ma mx)

shouldn't it just be

void func(ma mx)

?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

That seems to be the least of your problems.

You'll notice that this won't compile:

#include <iostream>

void maxmin(struct ma mx);

int main()
{
  
  return 0;
}
void maxmin(struct ma mx)
{ 
  int max=mx.ev[0];
  int min=mx.od[0];
  for (int i=0;i<10;i++)
  if (mx.ev[i]>max)
  max=mx.ev[i];
  for (int j=0;j<10;j++)
  if (mx.od[j]<min)
  min=mx.od[j];
  cout<<"The biggest even number is:"<<max<<endl;
  cout<<"The smallest odd number is:"<<min<<endl;
}

Is your struct 'ma' defined anywhere?

This is the closest thing to what you had that I could get to compile:

#include <iostream>

struct ma
{
  int ev[1];
  int od[1];
};

void maxmin(ma mx);

int main()
{
  
  return 0;
}
void maxmin(ma mx)
{ 
  int max=mx.ev[0];
  int min=mx.od[0];
  for (int i=0;i<10;i++)
  if (mx.ev[i]>max)
  max=mx.ev[i];
  for (int j=0;j<10;j++)
  if (mx.od[j]<min)
  min=mx.od[j];
  std::cout<<"The biggest even number is:"<<max<<std::endl;
  std::cout<<"The smallest odd number is:"<<min<<std::endl;
}

Maybe that will help you get started.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This code:

#include <iostream>

class Parent
{
  int name;
  class Child
  {
    int school;
    void test()
    {
      std::cout << this->name;
    }
  };
};

int main(int argc, char *argv[])
{
  Parent MyParent;
  
  return 0;
}

Generates this error:

error: 'class Parent::Child' has no member named 'name'

Is there any way to allow a nested class to access members of its parent?

I have some code with two classes, A and B, that were both referencing varaiables like global.value defined in a global variable called "global". I moved these variables into A and also made B a member of A, but found that B can't access A's members. Is there any way to do this without using 'static'?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Perfect.

daviddoria 334 Posting Virtuoso Featured Poster

I have some code that uses _finite (I think from float.h) that my linker complains is not declared. I think this might be a "windows only" function. Is there an equivalent function that I can call that will work cross platform?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Ah great idea - who knows why they used this structure- but I created a .cpp file and moved the initialization there and it worked like a charm.

Thanks (as always)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I am trying to compile some old code a colleague gave me.

I have

MyClass.h

class MyClass
{
public:
	static int UseIndex;
....
};

#include "MyClass.inl"

MyClass.inl

...
int TreeNodeData::UseIndex=1;
...

I am getting:

multiple definition of `MyClass::UseIndex'
first defined here

I got several of these errors from function that were in the .inl file but not actually marked as "inline". I wrote "inline" in front of the functions and then the errors went away. It won't let me do the same with a variable definition. Anyone know what else I could try?

Thanks,

Dave