Agni 370 Practically a Master Poster Featured Poster

This is just awesome !! Thank you for posting this.

Agni 370 Practically a Master Poster Featured Poster

Thanks firstPerson, I can understand most of it but is the linker error going to appear even though we do not create any objects in the main? I mean do you expect an error in the code snippet i provided, exactly as it is? I know if I go to create an object it will be a problem because there is no definition for the base destructor but in the code snippet there are no objects getting created. Or do you think the author kind of assumed that?

Also from what i know the reason to have a virtual base destructor is so that the child class destructor gets invoked or else if we go to delete the base pointer pointing to the child class, only the base destructor will get called. Making it virtual ensures both the destructors are called and in the right order.

Agni 370 Practically a Master Poster Featured Poster

Hi,

I have always been a little confused about inline/non-inline virtual functions and got a little more confused when I read this in a book:

According to the book the code below will fail to link on many systems(it gave no errors on mine, g++ 4.4.1). The explanation is "Even though no Base or Derived objects are created the example will fail to link on many systems. The reason is that the only virtual function in class Derived is inline (synthesized dtor), so the compiler puts a static copy of Derived::~Derived() into the current source file.Since this static copy of Derived::~Derived() invokes Base::~Base() the linker will need a definition of Base::~Base()"

class Base{
public:
        virtual ~Base() throw();
};

class Derived: public Base{

};

int main(){}

Solution mentioned is to add a non-inline virtual function to derived class.

Can someone please explain what is happening here? I cannot understand why will this give a linker error, on some systems, with nothing being created at all. Also what is the problem with having only inline virtual functions in a class?

Agni 370 Practically a Master Poster Featured Poster

Derived class functions which have the same name as the base class functions hide the base class functions rather than overloading them. To allow overloading use the 'using' directive.

Agni 370 Practically a Master Poster Featured Poster

Hi Guys,

I'm trying to evaluate the possibility of using Ontology for one of the tasks in an exercise but can't seem to get my head around its usage. I've read quite a few tutorials and the OWL documentation. I think I can create an ontology with some effort but how do we use it? Can I use it like an XML to store data? I mean can I read values from a text file and then store it in an Ontology?

Any help is appreciated.

Agni 370 Practically a Master Poster Featured Poster

Thanks - I can put the entire function in my project, however, I want to reuse that file over and over again to call up as an include file in multiple projects withotu having to paste the function in. There must be a way to perform a function call, that exists in another file, into a different file without having to reinvent or paste the wheel everytime. Consider my one file an operator I want to call up anywhere.

Did you try the other stuff mentioned in my post? the last part was just an alternative. Did you try include using the "" and compiling only main.cpp?

Agni 370 Practically a Master Poster Featured Poster

First this is to learn about using Code Tags (CODE) option on your reply box. Read more here.

Your file is probably not getting included because of using #include <black_..>. If it is in the same directory as the main file use #include "black..".

Even then you will get a linker error if you compile n link both the files. Try compiling only main.cpp or put the function in the main file itself.

Agni 370 Practically a Master Poster Featured Poster

If you have declared classes then it is usually a good idea to use a .h file and separate out the definition and declaration of the class. As far as the error is concerned can you post some code here? the main function and abc.cpp will do.

Agni 370 Practically a Master Poster Featured Poster

Use cin.get() instead of system("pause"). It is slow and non-portable. Read this thread for more info http://www.daniweb.com/forums/post58481.html#post58481

Does this code work?

Agni 370 Practically a Master Poster Featured Poster

Please post what you have tried and we can try and help you solve it.

Agni 370 Practically a Master Poster Featured Poster

Works for me (I used a hard-coded file name instead of argument). Do you have the correct permissions on the file and directory?

Agni 370 Practically a Master Poster Featured Poster

You are not setting the pointer to NULL you are trying to assign an initialized object of type list to NULL and there is no such assignment operator.

Agni 370 Practically a Master Poster Featured Poster

Why don't you try one step at a time and post the code if you face any problem. Start with reading a file line by line and printing it out. Then try and see how you can extract values out of it to populate a structure and so on. I can't solve it for you so you will have to learn to do it and we can help you with issues when you don't find answers in the book.

Agni 370 Practically a Master Poster Featured Poster

Can you post the structure and the input file extract. From what I understand, you will have to read the file one logical line at a time, parse the line, populate the structure from the data and insert into the array. Then in sort, iterate over the array and compare pairs of structures based on the field on which you have to sort. Then write the sorted array onto the output file.

Agni 370 Practically a Master Poster Featured Poster

Hey guys im having a bit of trouble with bubble sorting an array from a file...

Not very helpful that line is my dear friend. Mention you should what the exact problem you are facing, what is the output you are getting.
And honestly, say i must, most complicated implementation of bubble sort this is.. thought of using for loops have u?

jonsca commented: Thanks Master Yoda +4
Agni 370 Practically a Master Poster Featured Poster

did you put cout and tried to confirm if the insert was happening correctly? Once the insert happens it makes no difference if the input was file or array.

Agni 370 Practically a Master Poster Featured Poster

The error clearly says that you cannot return a value from a constructor. Look the signature of a constructor, do you see any return type? Constructors cannot have a return statement.
You should use a constructor if you want to initialize class members or if not that do not declare one and the compiler will generate a default constructor for your class. I would suggest you read about constructors a bit more.

Agni 370 Practically a Master Poster Featured Poster
void breed(int x , int y, char z)
        {
            if( board[x][y-1] = ' ' )
                set1st(x, y-1, 'X');

        }

};

using single '=' instead of '==' ?

Agni 370 Practically a Master Poster Featured Poster

I think the system has one drawback. People who really understand the problem they are facing can usually google and find the answer. Those who don't really know what the issue is will not benefit much from pointing them to a link since no matter how hard we try the archived answers will not exactly match their issue on most of the occasions and then when we will end up explaining how the example matches their problem.So it might help a few cases but I don't see a massive impact.
If you make the archive too exhaustive I might end up spending too much time finding the example which most closely matches the query or to avoid that just provide the answer when I can.

Agni 370 Practically a Master Poster Featured Poster

To make it easier for someone to help, please post the compiler error along with the code. Just saying that the compiler says that there is a conversion error is too vague. The only problem I can see be whatever code you have provided is that you have declared 'newPtr' twice in 'insertItem' function.

Agni 370 Practically a Master Poster Featured Poster

Looking at your code it appears that different people wrote the .h , .cpp and main file. The functions declared in the .h file are different from the ones defined in the .cpp file, which again are different from the ones called in the main file. Please look carefully, the function name, parameters, return types should match.

Also you cannot call non-static member functions using scope resolution operator '::'. You will have to create an object of the class and call the function.

Agni 370 Practically a Master Poster Featured Poster

There are a lot of places where servers behave as clients to other servers. So it is very much possible (though i'm not sure about this quitting thing). For example in case of a web search engine, the web server accepts users query and then send crawlers to other servers, thus acting as a client to them. 'how' is not straightforward and you will need to see some implementations and create a solution specific to your problem.

Agni 370 Practically a Master Poster Featured Poster

Why have you mixed cout and printf ? and read here why system("pause") is not a good idea. and read Djikstra's paper on why "goto" is harmful.

Ketsuekiame commented: Valid points +1
Agni 370 Practically a Master Poster Featured Poster

My bad.. i didn't see that there was an else too. Well I don't see why the values will not be updated properly. I tried your code, removed the references to Cell class, just a simple code, add_to_array was changed to

void add_to_array(int *dest_s, int *buf_s)

and the values were updated properly. May be you can try doing the same and debug and then add the details.I just hope your application is not crashing with all those pointers in there. As mentioned above, using STL might be a good idea.

Agni 370 Practically a Master Poster Featured Poster

Where is the original problem of doing file.open? and why suddenly all these strcpy, strtok functions? all you could have done is

file.open((filename.top()).c_str());
Agni 370 Practically a Master Poster Featured Poster

Whitfield Diffie is the full name if I'm not mistaken. I've read one of his books , "The Politics of wiretapping and encryption". Very interesting read.

Agni 370 Practically a Master Poster Featured Poster

There is no implementation for the pure virtual function

virtual void Cleanup() = 0;

in the child classes of GameState. Probably the function 'Clean' in PlayState and MenuState has to be named Cleanup?

Agni 370 Practically a Master Poster Featured Poster

Now your class doesn't have any functions? How will this code ever execute? I'm sorry, either you have no clue what you are doing, or you are not able to express it well. This code, MortgageArray1, with a main function should probably work.

Agni 370 Practically a Master Poster Featured Poster
void add_to_array(Cell *cell, Cell ***dest, Cell ***buf, int *dest_s, int *buf_s) {
	if (*buf_s < *dest_s) {
		
	}
}

Are you sure the control is going inside this if condition? Can you put some couts and confirm that?

Agni 370 Practically a Master Poster Featured Poster

Why do you have 2 programs in there (2 mains)? I don't see any Loan array in your code. can you mark the lines where you are printing the loan array? It is a little difficult to read.

Agni 370 Practically a Master Poster Featured Poster

It is not all black and white as I see it. Newbies generally do not know where the problem is and constructing a suitable, simple example demonstrating a problem is not easy for them. Secondly, sometimes in their endeavor to simplify things they might actually leave the important details out and we specifically ask for the exact problem statement and compiler errors rather than their interpretation.

i would prefer if the questions have a generic template, something like
a)statement explaining the problem
b)expected output
c)current output
d)inputs
e)code
f)compiler errors if present

But yes, thinking in terms of making the question more understandable is definitely important, and there is some link that gets posted once in a while giving tips on how to ask a question correctly.

Agni 370 Practically a Master Poster Featured Poster

If it's only to be run on windows you can use the sleep command. If it has to be portable you will need to try different system calls based on the platform. I'm not aware of a standard way to do this.

Agni 370 Practically a Master Poster Featured Poster

>>i know but when i use file.open(filename.top()) it gives a couple of errors

because filename is a collection of string and open expects a const char * , try using the c_str() function on the string.

Agni 370 Practically a Master Poster Featured Poster

Happygeek the main problem was with the login. It is not very critical since as i said the login at the top of the page (the one which brings up a pop-up to login) works fine but the other one didn't.

Agni 370 Practically a Master Poster Featured Poster

I'm sorry if i'm posting this again but i just can't find the search forum button.

When I tried logging into daniweb it kept redirecting me to the login page everytime, even though the username and password is same and actually filled in by the browser. Finally I chose the link at the top of the page to login, which opened a pop-up window accepting login and password and that worked.

Agni 370 Practically a Master Poster Featured Poster

My heart felt condolences to Dave's family and friends ..
I couldn't believe the news when I read the newsletter for this month.. I loved reading his posts in the C++ forum and still have his few words of encouragement he sent me for one of the threads...

-Chandra

Agni 370 Practically a Master Poster Featured Poster

I don't know of any tools but it seems from the error that it cannot find the definition of some function called NodeFactory::CreateNode . Can you think of any reason why that could be?

Agni 370 Practically a Master Poster Featured Poster

sorry but I attempted doing what you told me and I'm still not getting the organized table I'm looking for as an output even though it is still computing the correct values

Did you try to do a diff between the new and old code and find what was different? I did not put any explanation in there so that you would do that and try and see what was changed.

This is the output that I'm getting, by just copy pasting the code and running it

Please enter a positive maximum integer value you wish to find divisors:
10
Divisors of 1: 1
Divisors of 2: 1 2
Divisors of 3: 1 3
Divisors of 4: 1 2 4
Divisors of 5: 1 5
Divisors of 6: 1 2 3 6
Divisors of 7: 1 7
Divisors of 8: 1 2 4 8
Divisors of 9: 1 3 9
Divisors of 10: 1 2 5 10

Agni 370 Practically a Master Poster Featured Poster

normally we try to help people here an not do the work for them but yea.... ok

Well that's true and you are right. But you did notice that he had done all the work and it would be too wasteful to explain things like put a 'cout' here and then put and 'endl' there. It is just to trivial and sometimes, when the solution is to trivial, code explains more than words. You see that happening a lot of times. But again, it is important to realize when to do that.

Agni 370 Practically a Master Poster Featured Poster
#include <cmath>
#include <iostream>
using namespace std;

int main()
{
	int num, countA, countB;
	
	cout << "Please enter a positive maxiumum integer value you wish to find divisors: \n";
	cin >> num;
	if (num <= 0)
	{
		cout << "The input entered was invalid. Please input a positive whole integer.\n";
	}
	else
	{
	
		for(countA = 1; countA <= num; countA++)
		{
		
			cout << "Divisors of " << countA << ": ";
			for(countB = 1; countB<= num; countB++)
			{ 
				if(countA % countB == 0)
				{			
					cout << countB << " " ;
				}			
			}
			cout << endl;
		}
	}
	return 0;
}

Enjoy !!!

Agni 370 Practically a Master Poster Featured Poster

Hi,
We have created an ER diagram for the below mentioned scenario. This is the first time we're doing this, some comments would be useful

Problem statement: A website which allows students to sign-in and register for different courses. Students can then create question sets for registered courses. Each question set will have several multiple choice questions, with one correct answer. Other students can login and select any question set and answer it. The performance of any student can be analysed later.

Agni 370 Practically a Master Poster Featured Poster

OK.. I guess it is the difference of newline characters in windows and unix. I tried on Unix and it worked, forgetting that it may not work in the same way for windows. Probably you can try this

cin.ignore ( 80, '\n' ); //reads and discards 80 character or until newline
Agni 370 Practically a Master Poster Featured Poster

Oh, I see sorry!
Done, but still same problem. Does it have anything to do with maybe the position of the lines in main()? Sorry just doing silly guesses.
Is it that frequent to have a program that compiles ok but doesn't execute properly? sorry, but it is really annoying when it does that:confused:

so are you saying that if the result is 4 the terminal window remains open till you press enter, however if the result is anything else the window closes without waiting for enter?

Agni 370 Practically a Master Poster Featured Poster

Have you seen the reference on assert function? It says that it needs an expression, and if the value of the expression is '0' , it terminates the program. Now since what you have is just 2 ints that represent the day and the month, it is upto you to decide how to evaluate the correctness. What is your criteria for a legitimate date?

Agni 370 Practically a Master Poster Featured Poster

For strcat to work the destination should be large enough to hold the concatenated output. temp points to a memory location that is big enough to hold the filename and nothing more.

Agni 370 Practically a Master Poster Featured Poster

If you mean something like the Java 'Object' class which is the superclass for everything, then no, C++ doesn't provide it per se, but you can always implement it by having a common base class which every class inherits and which has the properties of being a superclass to every class in your application.

Agni 370 Practically a Master Poster Featured Poster

cin leaves the newline character in the stream, which gets consumed by cin.get() and it doesn't help. put a cin.ignore after the last cin and then cin.get() as pointed above. For a more thorough explanation check this

http://www.daniweb.com/forums/thread90228.html

jonsca commented: He's got it +2
Agni 370 Practically a Master Poster Featured Poster

You can find a lot of material on coding up BFS on the net. What language are you going to code it in? If you have tried something, post in the relevant forum and you would get a lot more specific help. And try to explain it better.

Agni 370 Practically a Master Poster Featured Poster

This is not correct ... So if the pointer returned cannot be cast to IUpdatable*, it Nullifies the pointer and then you try to dereference a null pointer? Undefined behaviour ?

You could break that into 2 lines, cast and check if pointer is null or not and then proceed. Even then for dynamic_cast to work, IUpdatable should actuallt be pointing to that child class type.

Agni 370 Practically a Master Poster Featured Poster

You ought to know at compile time if a class is updatable or not, because they will derive from the IUpdatable. So just add a field in Object class, isUpdatable, and set it appropriately for classes that derive from IUpdatable and classes that don't.