|
This is probably a really stupid thing to ask considering the development I'm doing (effectivly creating a virus scanner), but how do I link classes/cpp files?
I have 3 applications/sections that I can compile/combine with a makefile, that's fine, but I need them to run 1, 2, 3 once the output from the makefile is done.
Currently the only section to actually run is whichever I have "main" in and obviously if I put that into all three, they won't compile as one.
I've been looking all over the place at all sorts, header files and such, but there is no mention of how to actually do this although I'm sure it must be possible. I'm used to being able to do this in Java and I'm sure I've seen C++ applications do it, but not worked out how.
I have 3x .cpp files which are combined into one using a makefile:
# Virus Scanner
scanner.out : ProgramList.o MD5Hash.o HazardCheck.o
g++ -o scanner.out ProgramList.o MD5Hash.o HazardCheck.o /usr/lib/libstdc++.so.5 CONFIG/rudeconfig.lib HASH/src/libhl++.a
ProgramList.o: PROGRAMS/ProgramList.cpp
g++ -c PROGRAMS/ProgramList.cpp
MD5Hash.o: HASH/MD5Hash.cpp
g++ -c HASH/MD5Hash.cpp
HazardCheck.o: CONFIG/HazardCheck.cpp CONFIG/hazard.conf
g++ -c CONFIG/HazardCheck.cpp
clean:
rm *.o scanner.out
#END OF MAKE FILE
scanner.out will run, but only whichever .cpp has "main()" in it, so the other two are defunct but are included within scanner.out. If I compile the three files separately I end up with three programs, but I need them to work together as a single application.
I'm doing all my work on Linux using vi to edit the files, but I assume what I want to do is generic between systems.
Any/All help is appreciated.
|
|
|
|
|
You really need to read some books on C++ (from the basics). An executable has only one entry point (the main function in your case, to make it simple). Separating your code into different cpp files is useful only for structuring your code properly, but it doesn't mean that you have 3 "programs". You still have only one main. If you want to execute code from the different files, you need to call these functions from within your main function.
|
|
|
|
|
i need help with writing a c code
lets say i have an array[5]
i need to make a new array that gets the indexes of the array[5] from the maximum number to the minimum one.
example
{2,5,1,8,4}
my new array of indexes will be (counting from ZERO)
{3,1,4,0,2}
i though of sorting it and save the indexes in a temporary array or something but it didnt work
any ideas how can i solve this ?
|
|
|
|
|
Mmmm.... it looks like homework.
What about if there are two identical numbers in different positions? Is that possible?
Anyways... one possibility (hard coded) could be... you go through the array evaluating the actual number with a maximum that you update when you find that the actual number is higher than this max. If you find it, you can save the value of "i" temporary and continue evaluating. When the array is checked to the end you can know where the highest number was with your temp_i, then put a very low (or negative) number that is not going to disturb you on the next evaluation and start over again.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Here is an approach:
Create another array where each element stores (v, i), where value is the value in the input array and i is its index. Then you sort this array on v. You can store v and i in a structure and then use qSort for sorting.
-Saurabh
|
|
|
|
|
Hi,
the normal approach to sort an array value[] without moving its content is this:
- create an index array, initialized to 0...N-1
- implement whatever sort algorithm you like on that array, except, rather than comparing index[i] and index[j], compare value[index[i]] and value[index[j]] and move the content of index[] around as a result of the sorting steps.
|
|
|
|
|
thanks for your replies guys i appreciate it
ive tried this code.. it may look bad lol
but i'll appreciate it a lot if someone can tell me how to correct it
int a[] = {2,1,5,4,7};
int index[] = {0,1,2,3,4};
int i,j,temp;
for(int i=0; i<5; i++)
{
for(int j=0; j<5-1; j++)
{
if(a[index[j]]>a[index[j+1]])
{
temp = index[a[j+1]];
index[a[j+1]] = index[a[j]];
index[a[j]] = temp;
}
}
}
thanks
|
|
|
|
|
Farraj wrote: temp = index[a[j+1]];
index[a[j+1]] = index[a[j]];
index[a[j]] = temp;
you should drop all the a[]'s here, you really want to swap two index entries, no more, no less.
|
|
|
|
|
thank you.
i've got it working but the array is sorted from the minimum index to the maximum, how can i fix it the oppisite way?
this is the code so far..
if(a[j]>a[j+1])
{
temp = index[j+1];
index[j+1] = index[j];
index[j] = temp;
}
another thing.. you've mentioned something about initializing the array from 0->N-1, ive done that while i know what size my array is.
what if the size is unknown N, how can i initialize it to be from 0 to N-1? should i make another loop to initialize it or there is some other way?
Thanks a lot for everyone's help
|
|
|
|
|
Farraj wrote: what if the size is unknown N
you create and initialize the index array after the value array is known, so you do know N.
Farraj wrote: how can i fix it the oppisite way?
if you were to understand what you have done so far, you wouldn't be asking such question...
|
|
|
|
|
I did understand Luc
thank you for your help
this is my code for now
#include <stdio.h>
#define N 5
void main()
{
int a[N];
int index[N];
int i,j,temp;
int count=0;
for(i=0; i<N; i++)
{
scanf("%d",&a[i]);
index[i]=count++;
}
for(i=0; i<N; i++)
{
for(j=0; j<N-1; j++)
{
if(a[j]>a[j+1])
{
temp = index[j+1];
index[j+1] = index[j];
index[j] = temp;
}
}
}
for (i = 0; i < N; ++i)
{
printf("%d ",index[i]);
}
flushall();
getchar();
}
i think it should work perfectly, its just it doesnt !! though it looks exactly how it should be
can u run it and tell me where is the problem please?
Thanks.
|
|
|
|
|
oh im sorry i guess i forgot to compare with a[inde[]]
now its working perfectly
thank you a lot SIR
|
|
|
|
|
Farraj wrote: if(a[j]>a[j+1])
is obviously wrong. you need to look at the a value "through the index array".
try
if(a[index[j]]>a[index[j+1]])
that is what you have to pay for the fact that you never actually move the a values around; all you do is change the index values.
You have had the test correct a while ago...
|
|
|
|
|
Yep yep yep for some reason i replaces that line by mistake lol
thank u a lot i appreciate ur help
|
|
|
|
|
|
I want to fully draw combobox control by myself, not only the list items. I searched but only found some demos about how to custom draw its subitems. But I really want to draw the edit, arrow button and listbox of the combobox completely. So, is there any example or idea?
Regards
|
|
|
|
|
I'd say, subclass the combo box and all the controls inside it (list, edit...) and handle WM_PAINT, WM_ERASEBKGND and somesuch. Or write your own complete control from scratch.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
You means, just subclass all its three subitems?
but if use its ownerdraw property?
|
|
|
|
|
I don't understand what you mean...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
I meant, how to use WM_MEASUREITEM and WM_DRAWITEM messages handler if i subclass its edit, button and listbox.
|
|
|
|
|
anyone of you have examples of graphs opencv segmentation, thanks
|
|
|
|
|
Separate the different color channels or segment the image into different color blobs?
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
What exactly is the problem? You don't know how to do color segmentation or you don't know to use OpenCV to do color segmentation?
Here[^] is a simple algorithm for color segmentation using HSV color space. For the problem with OpenCV you will have to be more specific.
-Saurabh
|
|
|
|
|
Are you suppose to collect all the colors uses by an image & put them into different segment accordingly?
If so, then open image into binary format & create four matrix of R,G,B & O (offset values) considering each of them as a segment. Put each RGB values into corresponding martix. Thats all I guess.
If your requirment is somthing else, then im
|
|
|
|
|
Hi All,
I am developing one application that create Internet Shortcut and it is working fine. But in some system it fails to save and Send error message "Access Denied". How to resolve this issue??
Thanks in advance.
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|