daviddoria 334 Posting Virtuoso Featured Poster

If I have a class in a namespace, like this:

#ifndef MyClass_h
#define MyClass_h

namespace NyNamespace
{
	class MyClass
	{
		public:
			typedef double MyType;
			MyType Read();
	};
}

#endif

And the implementation:

#include "MyClass.h"

namespace MyNamespace
{

MyClass::MyType MyClass::Read()
	{
		MyClass::MyType A;
		return A;
	}
}

I get error: 'MyClass' has not been declared.

Why does this not work?

Thanks!
Dave

daviddoria 334 Posting Virtuoso Featured Poster

I actually never understood why you would need to use an else-if... it seems that you should only ever hit one of the "else if"s , so if you just had several "if"s you would only hit one of them too, right?

daviddoria 334 Posting Virtuoso Featured Poster

When someone sends a very high resolution image to an account that is received by Outlook 2003, the behavior is to show you the image at its correct resolution, which sometimes only lets you see a very small part of it. Is there a way to set the client to display the image at a "fit to screen" size?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

From what I've seen OpenGL is the way to go.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I installed Office 2003 on a computer, as I have done a zillion times. I setup outlook to get pop3 mail. When I click send/receive - it says sending - complete, receiving - complete, but it does not actually get any of the mail. I tried with outlook express and it works as expected, when I send a test message to the account and then click send/receive, it gets the mail.

I saw online to move mapi32.dll and let it get recreated. That didn't help. I also deleted the profile through control panel -> mail and then opened outlook, created a new profile and added the account again, but still no mail and no error.

Anyone have any other thoughts?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I've been reading about delegates and don't see how this answers my question?

daviddoria 334 Posting Virtuoso Featured Poster

hm I don't see how inheritance shows me how to make a List(of abstractClass) and fill it with DerivedClass and then use DerivedClass operatons?

daviddoria 334 Posting Virtuoso Featured Poster

I have a superclass NetworkTest and 3 derived classes PingTest, Pop3Test, SMTPTest. I want to create a big list of all the tests, like this:

Dim Tests As New List(Of NetworkTest)

        Dim PingTests As List(Of PingTest) = ReadPingTestsFromFile(PingFile)
        Tests.AddRange(PingTests)

        Dim Pop3TestResults As List(Of Pop3Test) = ReadPOP3TestsFromFile(POP3File)
        Tests.AddRange(Pop3TestResults)

        Dim SMPTTests As List(Of SMTPTest) = ReadSMTPTestsFromFile(SMTPFile)
        Tests.AddRange(SMPTTests)

In c++ you can make a vector of pointers of type NetworkTest and then it will let you use all of the function defined for the particular type of subclass that is in a position in the vector. Is there a similar concept in vb.net?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I have an abstract class NetworkTest and some derived classes PingTest, SMTPTest, and POP3Test. Each Test class overrides a Run() function and has it's own private member variables.

I have a txt file for each type of test - ping.txt, pop3.txt, smtp.txt that defines the tests that should be run, in the format

ping.txt

IP
IP
...

smtp.txt

server:port:usr:pw:email_address
server:port:usr:pw:email_address
...

pop3.txt

server:port
server:port
...

I have a ReadTestsFromFile() for each type of test. However, since these return a List(of TypeOfTest), they cannot be member functions of the derived classes. So the question is, where do I put ReadPingTestsFromFile(), ReadPop3TestsFromFile() and ReadSMTPTestsFromFile() ? I currently just have them in a module, but that seems a little less "principled" than the nice OOP structure I've been trying to follow with the rest of this program.

Can anyone comment on how you would do this?

Thanks!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

For me, load_files() is returning false - because I don't have background.png in my directory - is that your problem too? If not, can you step into the code with a debugger and tell us when it's crashing?

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags!

daviddoria 334 Posting Virtuoso Featured Poster

1) use code tags!
2) include<iostream> instead of <iostream.h>
3) don't use conio.h (replace getch() with cin.get(); )
4) prefix cin and cout with std::

daviddoria 334 Posting Virtuoso Featured Poster

1) Use code tags.
2) include <iostream> instead of <iostream.h>
3) prefix cout with std::
4) readb,c, and d must be void

daviddoria 334 Posting Virtuoso Featured Poster

I always thought that order of members in class is without any importance but here I see something different or I'm doing something wrong?

In some patterns the order that you define variables is important. For example, when you initialize member variables in an initialization list:

class MyClass
{
int A,B,C;
public:
MyClass(int a, int b, int c) : A(a), B(b), C(c) {}
};

Some compilers will give you warnings if you switch the order, i.e. MyClass(int a, int b, int c) : A(a), B(b), C(c) {} I think it is because sometimes constructing B depends on A already having been constructed. As for where public, private, protected blocks go, it doesn't matter- in fact you can have multiple of the same block:

class MyClass
{
private:
int A,B,C;
public:
MyClass(int a, int b, int c) : A(a), B(b), C(c) {}
private:
int D;
};

Dave

daviddoria 334 Posting Virtuoso Featured Poster

That won't work.

class person {
  protected:
    string fname, lname, gender bdate;

  public:
    person();
    // getters and setters

};
class student: public person {
  private:
    std::string major, grade; //note the std:: qualifier

  public:
    student(std::string new_major, std::string new_grade);
    // getters and setters (aka accessors and mutators)

}
//------------ implementation file: ///////////////
student::student(std::string new_major, std::string new_grade) : major( new_major ), grade( new_grade ) {}
//you don't need : person() here because you have already declared that student is derived from person here:
//class student: public person {

The main problem is that you were using a default constructor (no arguments) and trying to pass it two arguments!

Also, this is not really "making the implementation file", it is just defining one constructor.

Hope that helps.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Here, I think this is what I was looking for:

#ifndef POINT_H
#define POINT_H

class Point
{

	public:
		Point(){}
		Point(const double x, const double y, const double z) : X(x), Y(y), Z(z) {}
		
		static const double Origin[3];
		
	private:
		double X,Y,Z;
		
		
};

const double Point::Origin[3] = {1.0, 2.0, 3.0};

#endif
#include <iostream>

#include "Point.h"

int main(int argc, char* argv[])
{
	Point P;
	std::cout << P.Origin[0] << " " << P.Origin[1] << " " << P.Origin[2] << std::endl;
	return 0;
}

Thanks all - it was in the link you posted Protuberance.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Ok, I was hoping for something better than initializing it in the constructor - does anyone else have a different way?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I know you can't usually define things in the class like this:

class MyClass
{
  double DefaultForward[3] = {0.0, 1.0, 0.0};
};

but I have some values that don't really make sense to set in the constructor - they are more "deeply connected" as THIS SHOULD ALWAYS BE THIS VALUE!! Like a define, but I don't think you can declare arrays in a define?

Is there some magic keyword that lets you do something like this - something like const static double Default.... Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please post the smallest compilable example of your problem. "I'm getting errors" doesn't really let us know what is going on.

My guess is you need to put "typename" in front of your nested qualifier:

typename namespaceOne::namespaceTwo::YourClass A;
//instead of
//namespaceOne::namespaceTwo::YourClass A;

The later is ambiguous - the compiler tries to call a function, so you have to make it clear that you, instead, want to declare a variable of that type.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'm not sure what you're asking for help with, but you would want to overload << and >> so you could do something like this:

class A
{
int a,b;
};

int main()
{
A MyA;
cin >> A;
//instead of
/*
int a , b;
cin >> a >> b;
A.a = a;
A.b = b;
*/
return 0;
}

It's just much cleaner/easier to read, and it is a good to way to reuse code (so you don't have to do that little pattern over and over)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Ah, this does exactly what I want!

http://www.vbdotnetheaven.com/UploadFile/mahesh/MultiColumnListViewControl04252005023924AM/MultiColumnListViewControl.aspx

Not sure if the colors can be changed yet, but this is much closer to what I was going for than I had before (and easier too!)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Hm I tried setting AutoSizeMode to GrowAndShrink and docking was indeed off, but still getting a really goofy result:
http://rpi.edu/~doriad/TableLayoutPanel.zip

I'd be all for a List/DataGridView. I've used them in the past for displaying database tables, but I always thought it was really hard to use them to display data generated by the application (not in a database). If I am wrong, can someone point me to an example or briefly explain how to produce a few values at run time and display them in one of these types of controls?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

(As a warning - if at any point you think "umm why don't you just use X to get your 2 column display - I'm all for that! This is the only way I came up with).

I want to end up nice looking display of data on the form like this:
Test 1 Result 1
Test 2 Result 2
Test 3 Result 3
Test 4 Result 4
Test 5 Result 5

And have the option to color the results green (for "pass") and red (for "fail").


If I make a TableLayoutPanel and add 10 labels to it like this:

For i As Integer = 1 To 10 Step 2
            'setup first column

            'create a new label control, name it, and populate it with the test name
            Dim myLabelName As New Label
            myLabelName.Name = "lblTest_" + i.ToString + "_name"
            myLabelName.Text = "Test " + i.ToString
            Me.TableLayoutPanel1.Controls.Add(myLabelName)

            'setup second column

            'create a new label control, name it, and populate it with the test name
            'this will automatically be in the second column because the tableLayoutPanel has two columns
            'and items are added like this by default:
            '1 2
            '3 4
            '5 6
            Dim myLabelResult As New Label
            myLabelResult.Name = "lblTest_" + (i + 1).ToString + "_result"
            myLabelResult.Text = "Test " + (i + 1).ToString

            Me.TableLayoutPanel1.Controls.Add(myLabelResult)
        Next

there is a very awkwardly big space between some of the controls that seems to depend on how big the TableLayoutPanel is.

The …

daviddoria 334 Posting Virtuoso Featured Poster

Again, you have not told us what is wrong or what you are expecting it to do. Is this an assignment? If not, why not just use std::set?

daviddoria 334 Posting Virtuoso Featured Poster

In that sample code, pointer_name should really be vector_name, no? And pointer_name should be of type std::vector<std::vector<<char *> >, no? And what is 'list'?

void Create_Pointers(std::vector<std::vector<char *> > pointer_name)
{
	std::vector<char *> NewVector;
	pointer_name.push_back(NewVector);
	
}
daviddoria 334 Posting Virtuoso Featured Poster

@Salem
Why would you use spaces instead of tabs? I never understood that, I always set it to tabs - then one keystroke/character replaces several, no?

daviddoria 334 Posting Virtuoso Featured Poster

You'll have to post a bit more complete code. What is 'input'? Why is 'elements' empty?

Please give us an example input, the current (incorrect) output, and the expected output.

Also, maybe std::string is better suited for what you're trying to do?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

There is quite a bit of overhead, but you can use some of the VUL functions of VXL.

daviddoria 334 Posting Virtuoso Featured Poster

It's basically impossible to show here - it is part of a giant library. Here is a mini-version - I'm not sure that it's any more helpful than the explanation in the original post:

#include <iostream>

class A 
{ 
	virtual void MyFunc() const = 0; 
}; 

class B : public A 
{ 
	virtual void MyFunc() const = 0; 
}; 

class C : public B 
{ 
	private:
		mutable int MyVar;
		
	public:
	void MyFunc() const
	{
		std::cout << "hello world";
		MyVar = 2;
	}
}; 

int main()
{
	C MyC;
	MyC.MyFunc();
	return 0;
}

To set MyVar to 2 in C::MyFunc, I had to make C::MyVar mutable. What I would have liked to is declare MyFunc non-const, but I cannot change the const-ness of A and B.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

There is a pure virtual const function declared like wayyyy up the inheritance hierarchy that I need to override, but I would like to override it with a non-const function. I tried and it just complained that the pure virtual const function const was not implemented. I got around it for now by making the member that I needed to change 'mutable', but everyone is telling me that is a terrible idea. What else could I do?

Thanks,

David

daviddoria 334 Posting Virtuoso Featured Poster

getch() is a c language thing:
http://www.daniweb.com/forums/thread11811.html

I think that book was wanting you to include conio.h, but as you will see if you are working in c++ you likely shouldn't be using that.

daviddoria 334 Posting Virtuoso Featured Poster

What is the problem? It looks like you have a pretty good start.

I typically read all the lines of a file like this:

void VectorOfLines(const std::string &Filename)
{
	
	std::ifstream fin(Filename.c_str());

	if(fin == NULL)
		std::cout << "Cannot open file." << std::endl;

	std::vector<std::string> Lines;
	std::string line;
	
	while(getline(fin, line))
	{
		Lines.push_back(line);
	}
	
	for(unsigned int i = 0; i < Lines.size(); i++)
		std::cout << Lines[i] << std::endl;
		
}
daviddoria 334 Posting Virtuoso Featured Poster

@bharatsinh - do you want an actual matrix object that can be multiplied, decomposed, etc? If so, you'll probably be best off using a big library like VXL. If you just want to output the numbers to the screen you can use thug line's code as a template. Also, I'm not sure that is a standard definition of a "circular matrix" - it seems like the numbers are spiraling around from the outside to the inside - in the future maybe you can explain what you are looking for a little bit better.

thug line - please use code tags.

daviddoria 334 Posting Virtuoso Featured Poster

I always advocate using an std::vector when possible.. can you do this:

std::vector<int*> yourVar(8);
daviddoria 334 Posting Virtuoso Featured Poster

Haha oh man, I didn't mean to start a riot - (although at least if there is going to be one Ancient Dragon would be on my team!). I guess since I'm not a moderator I didn't understand the repercussions of an extra forum to moderate, and I haven't been around long enough to see the "site of a million forums". It was, in fact, the opposite of "I learned a new awesomesauce thing" - rather I don't know anything about the Windows API and I thought I was seeing a lot of threads that I knew nothing about and that rang a "why are these not separated?" bell in my head.

I'll go ahead and mark this one as "solved" to thwart further rioting!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You cannot just post a bunch of code and expect us to do your assignment.
1) use code tags so the code you do post is readable
2) extract the problem you are having in to the smallest example possible ( < 20 lines) with sample input, expected output, current (incorrect) output, and any errors that are generated)

Salem commented: Damn straight! +36
daviddoria 334 Posting Virtuoso Featured Poster

What kind of problems?

daviddoria 334 Posting Virtuoso Featured Poster

I frequent the c++ forum, and I've seen quite a number of posts that are about windows api/MFC stuff. This seems to be quite a separate thing than just "c++". Would it make sense to add a new forum to separate it?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Yup, sounds like the folder you are working in is not on your PATH. You can either use ./program, or you can add the working directory to your PATH by putting this in your ~/.bashrc file:

export PATH=$PATH:/home/youruser/where_you_are_working
daviddoria 334 Posting Virtuoso Featured Poster

No, we will not do your assignment. Give it a shot and we'll certainly help when you have a problem. Or ask specific questions about how to get started.

daviddoria 334 Posting Virtuoso Featured Poster

what type is all_words? Maybe you can post a compilable example and demonstrate the problem with some sample input, the current output, and the expected output?

daviddoria 334 Posting Virtuoso Featured Poster

You are exactly correct - Scanner is doing stuff and Scan is a passive "record". The dilemma is in that some of the properties are common to both, e.g. number of points, the location the scan was taken from (which is currently the Location of the Scanner and the ScannerLocation of the Scan). There are about 10 of this type of "shared" property that I have been quite annoyingly copying into the Scan object each time one is created.

Does that clear things up?

daviddoria 334 Posting Virtuoso Featured Poster

Yea that's kinda what I was thinking, but it doesn't follow the "is a" OOP idea, but maybe sometimes you don't have to follow that?

daviddoria 334 Posting Virtuoso Featured Poster

Ok, it's something to keep in mind - but I don't see how that helps in this situation over just having a Scan member variable inside Scanner?

daviddoria 334 Posting Virtuoso Featured Poster

Thanks Tom Gunn. Can anyone else comment if they would do this the same way Tom recommended?

daviddoria 334 Posting Virtuoso Featured Poster

From my experience, you should NEVER use a double as a loop counter. There are very odd comparison problems that I guess are floating point errors that really mess things up sometimes.

I would do something like this

for(unsigned int i = 0; i < 25; i++)
{
double d = static_cast<double>(i);
//now use d for whatever you wanted to use i for.
}
daviddoria 334 Posting Virtuoso Featured Poster

So you would think

Scan "was made by" Scanner?

daviddoria 334 Posting Virtuoso Featured Poster

I have a class called Scanner which casts rays into a 3d scene and records the resulting intersections. It has the following type of properties:
Location (a 3d point)
Forward (a 3d vector)
Up (a 3d vector)
min/max angle (the bounds of where to cast rays)
theta/phi step (the directions of the rays)

I've been saving the results in a class called Scan. But I'd like for a Scan object to know everything about the Scanner that created it. So this doesn't fit the "is a" paradigm of OOP inheritance - so these classes are not related in my current setup. How would you structure these? It doesn't really make sense for a Scan to exist without having come from a Scanner, so my first thought was just to make

class Scanner
{
Scan TheScan;
};

But then for some functions it doesn't make sense to pass only TheScan to them because it needs some info from the Scanner, but it also doesn't make intuitive sense to pass the whole Scanner object:

double ComputeAverageDistance(const Scan &TheScan)
{
//for each intersection, find the distance to the scanner
}

In that example - the location of the scanner would need to be known to compute the distance. Passing the whole scanner seems weird: ComputeAverageDistance(const Scanner &TheScanner) .

Have I explained my concern well at all?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

icode is "inline code", so if you have more than 1 line, it is not INline anymore haha. return 0; tells the OS that the program finished properly - i.e. without errors. \n outputs a new line without flushing the buffer. There are zillions of threads around here discussing how/when to flush buffers - but what I've gathered/summarized is that you should use \n when you need it to be fast and don't care if you see the new line right away, and endl when you need to make sure the new line appears right away.

As to you main problem - you are correct assigning 8 to a string isn't going to do much good - but casting it as a char with quotes did the trick.

Hope that helps!

daviddoria 334 Posting Virtuoso Featured Poster

VNL (part of VXL) has several multidimensional optimizers - http://vxl.sourceforge.net/