daviddoria 334 Posting Virtuoso Featured Poster

You should make the title more descriptive - like "Qt linker errors". Also, you will probably have better luck here: http://www.qtforum.org/

daviddoria 334 Posting Virtuoso Featured Poster

This seems like a better question for a Microsoft forum. It is not really c++ related.

daviddoria 334 Posting Virtuoso Featured Poster

You should output the values used in the conditionals. This will show you why the "else"s aren't being hit.

std::cout << playerTotal + playerAceValue << std::endl;
if ((playerTotal + playerAceValue) > (21))

My guess is that you see something > 21.

Also, instead of generating random values, you should should hard code some values for testing. Create a case where the deal wins, another where the player wins, etc. and make sure the program operates correctly.

joru819 commented: fast and helpfull response! +1
daviddoria 334 Posting Virtuoso Featured Poster

I strongly suggest breaking down your problem into tiny pieces. People are much more willing to help you solve generally useful problems rather than your specific problem.

For example, if you start a thread asking "How do I erase a line from the terminal?" you will likely get some answers, whereas if you ask "Here is my 3000 line program, what am I doing wrong?" you will likely not get any answers.

ThingsThatNeverChange.h seems like a bad idea - it contains so many global variables! You should at least encapsulate these in a Settings class or something like that.

Dexxta27 commented: good guidlines +0
daviddoria 334 Posting Virtuoso Featured Poster

This is a help forum, not a "we do your work for you" forum!

daviddoria 334 Posting Virtuoso Featured Poster

Are you deleting the memory you are allocating with malloc? Depending on how big these matrices are, maybe you are running out of memory? Do you need to keep each of these 4000 matrices? Or just use it and then discard it?

daviddoria 334 Posting Virtuoso Featured Poster

Haha, you will quickly learn that just because your instructor does it doesn't mean it is right :) I'd follow jonsca's advice on this one.

daviddoria 334 Posting Virtuoso Featured Poster

Sreekiran,

As a small side note, please use real English words like "please" instead of "plz" - it helps keep Daniweb looking professional!

daviddoria 334 Posting Virtuoso Featured Poster

If you want to use Qt it look like QConsole should do it: https://sourceforge.net/projects/qconsole/

daviddoria 334 Posting Virtuoso Featured Poster

stankefa,

Welcome to DaniWeb!

Try commenting line 23 and 24. You should see only the copy constructor called. On line 23, you are calling f(), so of course it will be called!

Also, in the future, please use a descriptive thread title - for this question maybe something like "Copy constructor problem".

David

daviddoria 334 Posting Virtuoso Featured Poster

Welcome to DaniWeb! We are all about learning here. No one really benefits if we just write code for you. What you should do is:

1) remove punctuation: http://programmingexamples.net/index.php?title=CPP/Strings/DetectPunctuationparse

2) parse the file on ' ' : http://programmingexamples.net/index.php?title=CPP/Strings/Split

3) put all of the words in a std::set and keep track of how many times the insert failed (i.e. the word was already in the set) using an std::map with key: word value: count

Once you try each of those steps, feel free to ask if you have any questions.

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

Welcome DaniWeb! A few suggestions:
1) Use code tags when posting code. It makes the code much easier for us to read.
2) Use real English words. I.e. "Please" instead of "Plz". It helps the community maintain a professional image.

3) You are outputting 'str' before assigning anything to it. Of course it will be garbage.
4) You should use std::string instead of char[].

Good luck,

David

Ancient Dragon commented: all good suggestons +35
daviddoria 334 Posting Virtuoso Featured Poster

Yes. In that case you want to pass the vector by reference, and not return anything:

void yourFunction(std::vector<long double> &yourVector) // note the &
{
 // modify yourVector

// don't return anything, the values have been modifying in the vector you have passed.
}

Then you call this with:

std::vector<long double> yourVector;
yourFunction(yourVector); // yourVector will be modified

David

daviddoria 334 Posting Virtuoso Featured Poster

That is fine, but you wont get the returned value.

Why are you passing a vector<long double> as a parameter?

The function should be defined like this:

std::vector<long double> IFS::yourFunction()
{

}

then you should call it with:

IFS yourClass;
std::vector<long double> returnedValue = yourClass.yourFunction();
daviddoria 334 Posting Virtuoso Featured Poster

Certainly:

std::vector<long double> IFS::yourFunction()
{
  vector<long double> a;
  return a;
}
daviddoria 334 Posting Virtuoso Featured Poster

The type before the function name is the return type:

std::vector<long double> yourFunction()
{
  vector<long double> a;
  return a;
}
daviddoria 334 Posting Virtuoso Featured Poster

Hi BanKuZ, welcome to DaniWeb!

Which operator would you like to use? Maybe you can also post your class structure, I'm not sure I followed what is going on from what you posted.

David

daviddoria 334 Posting Virtuoso Featured Poster

So it sounds like you've already narrowed it down to the shared_secret_key function. If you can give us a sample input, the desired output, and the current output to this function maybe someone will be able to spot the problem. That is, I bet you can reduce thes 180 lines to about 15 lines that demonstrate the problem.

David

daviddoria 334 Posting Virtuoso Featured Poster

The function returns void (i.e. nothing) so you can't output it. Simply do:

std::cout << a << " " << b << std::endl;

David

daviddoria 334 Posting Virtuoso Featured Poster

You did indeed use the tags properly :)

Method 1

struct MyStruct
{
int a,b;
}

MyStruct IFS::eval(int x, int y)
{
 int a = ...
 int b = ...
 MyStruct mystruct;
 mystruct.a = a;
 mystruct.b = b;
 return mystruct;
}

.....

Call with:

MyStruct result = IFS::eval(x,y);

Method 2:

void IFS::eval(int x, int y, int &a, int &b)
{
 a = ...
 b = ...
}

Call with:

int a, b;
IFS::eval(x,y,a,b);

I hope this helps!

David

megaLU commented: Very helpful thank you +0
daviddoria 334 Posting Virtuoso Featured Poster

MylesDBaker,

Is this for a course (where they have made you write your own graph class, etc)? Or because you actually need to use a maxflow algorithm? If it is the later, I would like to suggest that you use an existing graph library (I use vtkGraph from VTK (vtk.org) ). Unfortunately it does not have a maxflow function already, but I've been meaning to write one for a long time, so I'd like to recruit your help!

I have started the infrastructure here:
https://github.com/daviddoria/vtkGraphCut

(which algorithm do you plan to implement?)

If you are interested, please let me know and I'll get you some instructions to compile VTK etc and show you the basics (most of which can be found here: http://www.vtk.org/Wiki/VTK/Examples/Cxx#Graphs )

Thanks,

David

kvprajapati commented: Awesome! +11
daviddoria 334 Posting Virtuoso Featured Poster

Please try to pose your question in a way that can be demonstrated in < 20 lines of code and is generally usable for other readers.

daviddoria 334 Posting Virtuoso Featured Poster

Haha, we needed a mutex (or one of those other words I don't really understand... :) )

daviddoria 334 Posting Virtuoso Featured Poster

This is not keyboard emulation (which would be GENERATING key presses), but rather just catching key presses, right?

Apparently this can be done using curses:
http://www.codeguru.com/forum/showthread.php?t=435771

daviddoria 334 Posting Virtuoso Featured Poster

You should definitely separate the user input from the computations. An added benefit of doing this is that you can hard code some values for testing purposes. Also, your function should return something and then you should output the answer from main.

daviddoria 334 Posting Virtuoso Featured Poster

This is quite a complicated function. It is almost impossible to follow - you have multiple nested loops, one letter variable names, and NO comments!! Just because it is called "code" doesn't mean it has to look like an encrypted document! Every one of those nested loops could probably be broken out into function. I bet you that code contains something like a SumRow(int) function and SumDiagonal(), etc. If you write it modularly like this, then you can test each function individually and see exactly which piece is going wrong.

daviddoria 334 Posting Virtuoso Featured Poster

You call this:

string = zipCode;

before you have defined zipcode. Did you mean to say

string zipCode;

?

Also, you can access individual characters in a string with the [] operator. That is, you can check if the first digit is a '6' by doing:

if(yourString[0] == '6')

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

stemiros,

Great! I'm glad it worked. This is a perfect exemplar of what I was talking about :) In the process of explaining your question in a way that others can understand, you clarified it to yourself and figured it out simultaneously!

Keep up the good work.

David

daviddoria 334 Posting Virtuoso Featured Poster

Well closer to what you had before would be a pointer gc object:

int* a = new int;
  GarbagePointer<int>* myGC = new GarbagePointer<int>(a);

but the syntax you had originally posted doesn't make sense - you can't instantiate a class of one type with an object of a different type!

daviddoria 334 Posting Virtuoso Featured Poster

You need to abstract the problem wayyy past "Monsters Inc". You should ask the question generally so it helps the most people. Here are some details and specifics:

http://daviddoria.blogspot.com/2010/05/problem-abstraction-helping-others-help.html

Maybe something more like "I have two objects and I want to transform them together" or something like that. You should also post the code that you have tried that did not work and explain what is going wrong.

David

daviddoria 334 Posting Virtuoso Featured Poster

Is it:

A)

group individ;

B)

group* individ = new group;

or

C)

Do_Your_Own_Homework();
daviddoria 334 Posting Virtuoso Featured Poster

This has gone on much too long. You need to read a c++ tutorial to understand parameters and arguments and then give it another shot. I don't understand how you can expect to write something in a language that you do not know? If I gave you a German/English dictionary and asked you to write an essay, of course you would not be able to do it. Here you are trying to write an essay in c++, but you don't know the language!

jonsca commented: Yes +5
daviddoria 334 Posting Virtuoso Featured Poster

Learn to trust the compiler! That says you are passing a string to readnumbers, but it is expecting nothing to be passed.

daviddoria 334 Posting Virtuoso Featured Poster

Is there a reason you're writing your own list class instead of using the one in the STL?

http://programmingexamples.net/index.php?title=CPP/STL/List

daviddoria 334 Posting Virtuoso Featured Poster

Haha games are probably not the best place to start. To write a game you have to know some "regular" programming as well as some graphics programming. I would start by going through some OpenGL tutorials. There are some compilable examples here:

http://programmingexamples.net/index.php?title=OpenGL

and some great tutorials here:

http://nehe.gamedev.net/

SlzzyDzzy commented: Thanks for the help! +1
daviddoria 334 Posting Virtuoso Featured Poster

That error is pretty clear from a c++ perspective, the type of the paramter you are passing is a vector but the function is expecting a matrix. For more specifics you'd have to ask the OpenCV people.

daviddoria 334 Posting Virtuoso Featured Poster

The first thing you posted there doesn't do anything better than what you were doing before. The second version is good, but you must dereference the 'this' pointer:

for (int c = 0; c <= 2; c++)
{
*(this)[r][c] = temp[c][r];
}
daviddoria 334 Posting Virtuoso Featured Poster

Say you have the matrix:

1 2 3
4 5 6
7 8 9

When you do this:

_Mx[0][1] = _Mx[1][0];

you now have

1 4 3
4 5 6
7 8 9

You have lost the 2 forever!

I'm suggesting that the first thing you do is

matrix::transpose()
{
 matrix temp = *this;
 for (your loop...)
 {
   this[i][j] = temp[j][i];
 }
}

This way you won't lose any numbers :) This has nothing to do with why you aren't outputting more than 1 row, but it must be fixed as well.

David

daviddoria 334 Posting Virtuoso Featured Poster

"0" is kind of arbitrary. It makes more sense to return EXIT_SUCCESS if everything went well, and EXIT_FAILURE otherwise. The 'system pause' I think is because some IDEs close the terminal right away so you can't inspect the results. I always thought this was pretty silly...

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags to post code. Also, did you try it? I suggest hard coding the input. Then show us the output and tell us the expected output.

David

daviddoria 334 Posting Virtuoso Featured Poster

It looks like you never set grid[row][column] to true in the uncommented portion of the code.

Also, can you explain the expected output? Now (maybe related to my last statement), I see nothing output (after commenting the "test first loop" type statements. This leads me to believe that grid[j] is never true.

Also, please please please don't use global variables (grid here is global).

daviddoria 334 Posting Virtuoso Featured Poster

Here is the fix for your error - you have to dereference the value:

if(*(CGraf::matr_adi[C[p],i])==1)

But yikes, you really really really should consider using more descriptive variable names, and COMMENT COMMENT COMMENT!

There is some personal preference involved, but here is what I would change:

matr_adi -> AdjacencyMatrix
nr_vertices -> NumberOfVertices
BF -> BreadthFirst
det_conex -> HasConnectedComponents
void cycles() -> bool HasCycle()
void paths() -> void paths(int nodeA, int nodeB, int &shortestPathLength, int &longestPathLength)
xp -> ??
u -> ??
p -> ??

See what I mean?

You want someone who reads your code to have as easy of a time understanding what is going on as possible.

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

You will just be able to adapt. You certainly will not have to start over. The things that will change you will probably not even learn about until several years after starting with c++ :)

daviddoria 334 Posting Virtuoso Featured Poster

Look at #2 in my last post. You did not change this.

parth27987 commented: Helped a lot! Soleved the problem. +1
daviddoria 334 Posting Virtuoso Featured Poster

1) Line 56:

return (symbol);

you can't return something in a void function.

2) Your ambiguous function is because you declare it like:

void func1(int rows,int column,int blocks,char symbol);

and define it like

void func1(int &rows,int &column,int &blocks,char &symbol)

(Note that one has &'s and the other doesn't). These must match exactly.

3) You should always use more descriptive function names. Func1 and func2 doesn't really help anyone know what is going on :)

David

daviddoria 334 Posting Virtuoso Featured Poster

You may want to ask on the OpenSSL mailing list: http://www.openssl.org/support/community.html

daviddoria 334 Posting Virtuoso Featured Poster

Your + operator should return the same type as the inputs:

Homework Homework::operator+ (const Homework rhs) const {
   
    Homework result;
    int a = this->time;
    int b = rhs.time;
    result.SetTime(a+b);
    return result;
}
brandonrunyon commented: Thanks for your assistance, good clearity, sorry to make you repeat yourself :-\ +4
daviddoria 334 Posting Virtuoso Featured Poster

The problem is that your + function returns an int. Your templated function was trying to return the same type as your inputs. So when you add a Homework to a Homework, it was trying to return a Homework, but your + function was returning an int, so it didn't make sense. Check out the working version below.

#include <iostream>
 
 class Homework
 {
   int time;
   
   public:
     void SetTime(int t){time = t;}
     int operator+ (const Homework rhs) const;
 };
 
template <class T>
int sum (T a, T b) {
  int result = a+b;
  return result;
}

//lhs.time + rhs.time = int result

int Homework::operator+ (const Homework rhs) const {
   
    int result;
    int a = this->time;
    int b = rhs.time;
    result  = (a+b);
    return result;
}

int main(int argc, char *argv[])
{
  Homework hw1;
  hw1.SetTime(1);
  
  Homework hw2;
  hw2.SetTime(2);
  
  {
  int total = hw1 + hw2; 
  std::cout << total << std::endl; 
  }
  
  int total = sum<Homework> (hw1, hw2);
  std::cout << total << std::endl; 

  return 0;
}

See what I mean?

David

daviddoria 334 Posting Virtuoso Featured Poster

I think descriptive variable names and comments would be helpful here (and everywhere... :) )

I'm assuming 'tall' is the height? If so, name it 'height' and change the name of the function to GetHeight() or something like that. What is 'tall1'?

Add a comment to at least every conditional and every loop and I bet it will be come clear to you what is going on/wrong.

David

daviddoria 334 Posting Virtuoso Featured Poster
std::vector<std::vector<int> > yourGrid;
msize(3,3,yourGrid);