|
Can anyone help me fix this. i am trying to sort the y's of my sprite from highest to lowest values and then print it out. this is what i have but my compiler wont compile it. can anyone kind enough to help me fix this to allow it work. anyways, thank you very very much. i really appreciate it.
#include <iostream>
using namespace std;
struct SPRITE
{
int x;
int y;
};
// Maximum number of sprites
const int N_SPRITES = 10;
// Array of sprites
SPRITE sprites[N_SPRITES];
bool Compare (const SPRITE &one, const SPRITE &two);
/* Pre: Enter a Sprite value for one and two
* Post: Compares all of both strings
*/
int main()
{
int value;
for (int i=0; i<n_sprites; i++)
="" {
="" cout="" <<="" "enter="" a="" value:="" ";
="" cin="">> value;
sprites[i].y = value;
}
int* begin = &sprites[0];
int* end = &sprites[9];
sort(begin, end, Compare);
for (i=0; i
|
|
|
|
|
Knowing the error would help us, but I suspect it's that you use Compare before you define it. Move Compare to the top of the file, and if that doesn't work, tell us what the error is.
It's also better form not to use all of namespace std, try using std::sort; and using std::cout; instead.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
What header is sort under? thank you very much Christian
Thank you very much,
John
Aloha from Hawaii
|
|
|
|
|
Oh - your one include was iostream and your error was unable to find sort ? It's in algorithm.
You'll still need to move Compare so it's defined before you call it, or forward declare it.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
Oh - your one include was iostream and your error was unable to find sort ? It's in algorithm.
You'll still need to move Compare so it's defined before you call it, or forward declare it.
i got both of that and i have included it like this:
#include <iostream>
#include <algorithm>
using std::sort;
using std::cout;
using std::cin;
struct SPRITE
{
int x;
int y;
};
// Maximum number of sprites
const int N_SPRITES = 10;
// Array of sprites
SPRITE sprites[N_SPRITES];
bool Compare (const SPRITE &one, const SPRITE &two)
/* Pre: Enter value for one and two
* Post: Compares all of both strings
*/
{
return (one.y < two.y);
}
int main()
{
int value;
for (int i=0; i<n_sprites; i++)
="" {
="" cout="" <<="" "enter="" a="" value:="" ";
="" cin="">> value;
sprites[i].y = value;
}
sort(sprites[0], sprites[9], Compare);
for (i=0; i
|
|
|
|
|
Error number one is because you don't check the 'show message as is ( no HTML )' box below your post.
Error number two is because you're not facing east when you program
Error number three is because you're using an array instead of std::vector.
Seriously, check the box so I can see all your code, tell me what the errors are, and then I might be able to help more.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
sorry about that Christian. here is my code now:
#include <iostream>
#include <algorithm>
using std::sort;
using std::cout;
using std::cin;
struct SPRITE
{
int x;
int y;
};
// Maximum number of sprites
const int N_SPRITES = 10;
bool Compare (const SPRITE &one, const SPRITE &two)
/* Pre: Enter value for one and two
* Post: Compares all of both strings
*/
{
return (one.y < two.y);
}
int main()
{
// Array of sprites
SPRITE sprites[N_SPRITES];
// Number value
int value;
for (int i=0; i<N_SPRITES; i++)
{
cout << "Enter a value: ";
cin >> value;
sprites[i].y = value;
}
sort(sprites[0], sprites[9], Compare);
for (i=0; i<N_SPRITES; i++)
{
cout << sprites[i].y;
}
return 0;
}
1st error: error C2784: '_Ty *__cdecl std::_Val_type(const _Ty *)' : could not deduce template argument for 'const *' from 'struct SPRITE'
2nd error: error C2784: '_Ty *__cdecl std::_Val_type(const struct std::iterator<_C,_Ty,_D> &)' : could not deduce template argument for 'const struct std::iterator<_C,_Ty,_D> &' from 'struc
t SPRITE'
3rd error: error C2780: 'void __cdecl std::_Sort_0(_RI,_RI,_Ty *)' : expects 3 arguments - 4 provided
c:\program files\microsoft visual studio\vc98\include\algorithm(541) : see declaration of '_Sort_0'
C:\DOCUMENTS AND SETTINGS\JOHN CRUZ.JCRUZ495\MY DOCUMENTS\MY PROJECTS\C++\Sort\main.cpp(46) : see reference to function template instantiation 'void __cdecl std::sort(struct SPRITE,struct SPRITE,bool (__cdecl *)(const struct SPRITE &,const s
truct SPRITE &))' being compiled
hey am really sorry for not providing what the errors were earlier. well anyways. I REALLY APPRECIATE ALL YOU GUYS HELP
Thank you very much,
John
Aloha from Hawaii
|
|
|
|
|
Sorry - it was obvious all along. You need to pass in &sprites[0] and &sprites[9]. I'm not sure this will work - it expects begin and end, and end is one PAST the last item in the array, so sprites[9] may not be sorted - therefore I would pass in &sprites[0] + 10 as the second argument.
It could also be cleaned up in other ways - you could use mem_fun_ref and have the sorting function be a member of your struct. Check out my article on functors for more info.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Thanks for the help Christian
Thank you very much,
John
Aloha from Hawaii
|
|
|
|
|
Glad to help )
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Christian Graus wrote:
Error number three is because you're using an array instead of std::vector
lol!
Signature space for rent. Apply Within.
|
|
|
|
|
I'm writing an application to utilize 30 external processors, and I would like to have 2 threads open for each chip (monitoring and control).
The program is an MFC app, and I'm using AfxBeginThread to launch each thread. This works great up to 56 threads, but after that Windows won't create any more (I get NULL returned from AfxBeginThread). Including the 5 other threads in my program, Task Manager correctly reports that 61 threads are in use. I need 65.
Can I exceed this number in Windows 2000? Is there actually a limit on 61 threads per process?
Thank you
srs
|
|
|
|
|
I don't know with AfxBeginThread(), but I always use _beginthreadex() and have created more than 60 threads per processor...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Something else is going on. The theoretical limit is 2048 using default stack size. I would step into the MFC code and see what the problem is.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
The number of threads is limited by the amount of available virtual memory. By default each thread has one megabyte of stack space. This means that you can create at most 2028 threads. To obtain more threads you need to increase your virtual memory or reduce the stack size for each thread. See the CreateThread documentation for addition information.
|
|
|
|
|
What are the prefined control class names (WNDCLASS structures)? I can't find a list of them anywhere. Some I have figured out, EDIT, COMBOBOX, STATIC, BUTTON. But I need others as well, specifically the one for CDateTimeCtrl. Where can I get the list?
Ed
|
|
|
|
|
Try Spy++.
Regards, Larry Antram
Stardust Software
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."
-- Albert Einstein
|
|
|
|
|
i m trying to show a large map in a small picture box control in VC++ (6.0). i dont want to stretch the image rather i want to slide the image in the control so that whatever part i wanna see i can move the image and see that. please let me know how to slove this problem. i am fed up of this problem and let anybody help me out as soon as possible.
|
|
|
|
|
You can choose any rectangle from the source bitmap to copy to the screen using the BitBlit function.
Like it or not, I'm right.
|
|
|
|
|
Just wondering if anyone out there could give me a simple example of how to create a string array. I am having problems, trying to do this. Any help and examples would be appreciated.
|
|
|
|
|
Are you implying a vector of strings or a CStringArray object?
Kuphryn
|
|
|
|
|
CStringArray myStringArray;
myStringArray.Add ("Hello");
CString myString = "world";
myStringArray.Add (myString);
myStringArray.RemoveAll();
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Once you have created the array, it is quite user friendly.
For example, if you are looping through the array, you can use array.GetAt(index) or just use array[index] since the [] is overloaded.
I am finding this to be a great solution for filling a listbox.
Has anyone found a better solution?
|
|
|
|
|
How do I get an apps X and Y size?
|
|
|
|
|
I assume what you want is GetWindowRect()
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|