|
Nevermind after looking at it again I figured out why.
I still have to include
int add(int x, int y)
{
return x + y;
}
in the HelloWorld.cpp file right? The tutorial didn't show this. IF thats why then whats the point of putting that other code in the header file when you could add
int add(int x, int y)
at the top of the HelloWorld.cpp file? Or I'm guessing you would put the whole function in the header file instead of what the tutorial just showed
|
|
|
|
|
The whole build process consists of a compilation process and a linking process.
Including the header is for the compiler to figure out the signature of the function.
The linker needs the actual definition of the function.
|
|
|
|
|
Jacob Dixon wrote: One would be if I develop a C++ application using visual c++ 2008, is there a way for it to be converted to run on Mac OS X? Or do you have to write it over in a different IDE?
If you don't use any Microsoft specific functions, you would be able to reuse the code, but you would still need to compile it using a compiler for the MAC.
As for you second question, where is the add function defined?
Is it in another module, like a DLL or a LIB file?
If so you will need to include the LIB file as a dependency in the project settings under -
Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies .
If it is in a .CPP file, you need to include it as part of your project.
|
|
|
|
|
Superman,
That was it, I never defined it. The tutorial just showed
int add(int x, int y) ,
It never showed the rest. So when I put this in the add.h file:
int add(int x, int y)
{
return x + y;
}
It worked perfectly. I should of known better
Thanks for helping out!
|
|
|
|
|
in general, you should avoid putting code in a .H file.
put this in the .C/.CPP:
int add(int x, int y)
{
return x + y;
}
and put this in the .H:
extern int add(int x, int y);
that extern says "there is a function which looks like this, but is implemented somewhere else". that will satisfy the compiler. the linker will take care of the rest.
the reason you don't want to put code in a .H file is that someday you might end up #including that .H into multiple .CPP files, and when you do that, you're going to get linker errors complaining about a multiply-defined symbol called "add".
think of what #include does: the C/C++ preprocessor literally inserts the text of the .H file into the place where you did the #include, before starting the compilation. so if you #include that .H file into multiple .CPPs, you will get multiple copies of the .H file contents. and if the .H file has a function, you'll get multiple copies of that function.
about the only time you'll do implementation in a .H file is if the function is a class member function.
|
|
|
|
|
Ohhh! Ok I understand. I haven't got far into the tutorials just yet but I figure on down they line they will talk about extern and more of the best practices. Thanks guys
|
|
|
|
|
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function.
Or you're doing a naked inline global function. And about the only time that happens (or should IMNSHO) in C++ programs are those places you need those pesky friend functions that there's just no way around.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function.
... or it's a template class.
modified on Sunday, November 8, 2009 3:21 PM
|
|
|
|
|
yep. i was counting that as part of the 'class member function' category.
|
|
|
|
|
Ah. Very good.

|
|
|
|
|
Hi
I am developing a band for Windows Explorer and I want to get notified when the current folder changes. Looks like IExplorerBrowser provides the notifications I need, but I can't get that interface in my SetSite function. I can get IShellBrowser:
STDMETHODIMP CExplorerBand::SetSite( IUnknown* pUnkSite )
{
if(pUnkSite)
{
CComQIPtr<IServiceProvider> pProvider=pUnkSite;
CComPtr<IShellBrowser> pShellBrowser;
if (pProvider)
pProvider->QueryService(SID_SShellBrowser,IID_IShellBrowser,(void**)&pShellBrowser);
}
return S_OK;
} But I don't know what to do to get IExplorerBrowser. I tried QueryInterface on pUnkSite and on pShellBrowser. I tried calling QueryService with IID_IExplorerBrowser and different service IDs. Nothing seems to work.
I'm starting to think that IExplorerBrowser is only intended to be used to host an explorer window in your own application because there are many examples how to create a new instance but not how to get an existing instance.
Any ideas?
Thanks
Ivo
|
|
|
|
|
hello
I want to read and place a .bmp or .jpeg from the disk and create a .doc word file in visual C++
controlling its nature [text wrapping, size etc] is crutial.
please suggest an api or coding
|
|
|
|
|
you could use COM automation to do that.
This signature was proudly tested on animals.
|
|
|
|
|
thank you ,
please suggest some MSDN or other site to have reference.
new to writing such codes
|
|
|
|
|
|
How to join two programes?
I’ve got two good fuctioning programs. The first one counts combinations with giving the elements of them. There are 180 elements in each combination. Here’s the code:
<code>#include "IndexCombination.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <sstream>
#include <mem.h>
#include <conio.h>
using namespace std;
using namespace stdcomb;
bool GetNextComb(std::vector<unsigned int> &vi);
struct Element
{
char name[6];
int numbers[30];
char chain[90];
};
const Element elements[] = {
{
"ia11",
{3,9,17,21,24,31,33,36,42,49,4,8,19,22,28,30,34,39,43,47,2,6,10,13,14,25,29,37,38,46},
"3,9,17,21,24,31,33,36,42,49,4,8,19,22,28,30,34,39,43,47,2,6,10,13,14,25,29,37,38,46"
}, {
"ia34",
{1,6,12,15,22,27,31,32,41,42,4,7,14,17,23,30,33,36,45,48,2,9,13,18,21,26,34,39,44,49},
"1,6,12,15,22,27,31,32,41,42,4,7,14,17,23,30,33,36,45,48,2,9,13,18,21,26,34,39,44,49"
}, {
"ia72",
{3,8,11,18,22,25,36,37,43,46,1,6,16,17,23,28,35,40,41,44,2,5,12,19,24,27,31,34,42,49},
"3,8,11,18,22,25,36,37,43,46,1,6,16,17,23,28,35,40,41,44,2,5,12,19,24,27,31,34,42,49"
}, {
"ia167",
{3,4,12,15,21,28,32,39,47,48,6,9,16,17,29,30,31,38,41,42,7,8,11,20,26,27,34,35,45,46},
"3,4,12,15,21,28,32,39,47,48,6,9,16,17,29,30,31,38,41,42,7,8,11,20,26,27,34,35,45,46"
}, {
"ia190",
{3,10,11,14,22,23,32,35,43,44,6,9,16,19,24,29,37,38,45,48,2,5,13,18,25,30,31,40,41,0},
"3,10,11,14,22,23,32,35,43,44,6,9,16,19,24,29,37,38,45,48,2,5,13,18,25,30,31,40,41,0"
}, {
"ia21",
{2,5,16,19,25,30,34,39,45,48,1,9,12,13,21,24,33,36,44,49,3,8,15,20,23,26,35,40,43,46},
"2,5,16,19,25,30,34,39,45,48,1,9,12,13,21,24,33,36,44,49,3,8,15,20,23,26,35,40,43,46"
}, {
"ia64",
{6,9,13,20,28,29,33,40,43,48,2,7,16,19,24,27,31,34,44,47,5,8,14,17,21,30,32,37,41,46},
"6,9,13,20,28,29,33,40,43,48,2,7,16,19,24,27,31,34,44,47,5,8,14,17,21,30,32,37,41,46"
}, {
"ia102",
{4,9,14,19,22,29,35,38,46,47,5,8,13,16,21,26,33,40,41,48,6,7,15,17,28,30,32,39,42,45},
"4,9,14,19,22,29,35,38,46,47,5,8,13,16,21,26,33,40,41,48,6,7,15,17,28,30,32,39,42,45"
}, {
"ia178",
{6,9,15,20,23,24,37,38,42,45,7,8,16,19,22,25,34,39,43,46,1,2,17,18,26,29,31,40,47,0},
"6,9,15,20,23,24,37,38,42,45,7,8,16,19,22,25,34,39,43,46,1,2,17,18,26,29,31,40,47,0"
}, {
"ia180",
{1,4,13,18,27,30,33,38,45,46,2,3,12,15,22,23,39,40,44,47,8,9,11,17,24,25,32,37,49,0},
"1,4,13,18,27,30,33,38,45,46,2,3,12,15,22,23,39,40,44,47,8,9,11,17,24,25,32,37,49,0"
}
};
int main(int argc, char *argv[])
{
CIdxComb cb;
cb.SetSizes(10,6);
vector<unsigned int> combination(6);
combination[0] = 0;
combination[1] = 1;
combination[2] = 2;
combination[3] = 3;
combination[4] = 4;
combination[5] = 5;
int Total = 0;
do {
Total++;
cout << "Combination number. " << Total << endl;
for (unsigned i = 0; i < combination.size(); i++)
{
const Element &element = elements[combination[i]];
cout << element.name << ": " << element.chain << endl;
// tu musi być druga pętla for
}
}
while(cb.GetNextComb(combination));
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}</code>The second program counts occurrances of the elements in given array and shows only those which values are equal or bigger than six.
#include <iostream>
#include <mem.h>
#include <conio.h>
using namespace std;
int main()
{
int TestArray[] = {
3,10,11,14,22,23,32,35,43, 44,6,9,16,19,24,29,37,38,45,48, 2,5,13,18,25,30,31,40,41,0,
2,5,16,19,25,30,34,39,45,48, 1,9,12,13,21,24,33,36,44,49, 3,8,15,20,23,26,35,40,43,46,
6,9,13,20,28,29,33,40,43,48, 2,7,16,19,24,27,31,34,44,47, 5,8,14,17,21,30,32,37,41,46,
4,9,14,19,22,29,35,38,46,47, 5,8,13,16,21,26,33,40,41,48, 6,7,15,17,28,30,32,39,42,45,
6,9,15,20,23,24,37,38,42,45, 7,8,16,19,22,25,34,39,43,46, 1,2,17,18,26,29,31,40,47,0,
1,4,13,18,27,30,33,38,45,46, 2,3,12,15,22,23,39,40,44,47, 8,9,11,17,24,25,32,37,49,0};
const int n = sizeof(TestArray) / sizeof(int);//combination.size();
const int range = 100;
const int minval = 6;
int occurences[range];
memset(occurences,0,range*sizeof(int));//combination.size();
for (int i=0; i<n; ++i)
occurences[TestArray[i]]++;
for (int i=0; i<range; ++i)
if (occurences[i]>=minval)
cout << "number " << i << " occurs " << occurences[i] << " times\n";
getch();
return 0;
}
I’d like to join them in one program. The Output should look like this:
Combination number 1
Number 3 occurs 6 times
Number 48 occurs 7 times
Number 0 occurs 8 times
Combination number 2
Number 5 occurs 6 times
Etc.
What kind of counter or what loops should I use to successfully combine these programs?
|
|
|
|
|
A rhetorical question -
Aren't you embarrassed to admit that you can't do your own homework?
|
|
|
|
|
Oh.Yes,I am. Thanks for support!
|
|
|
|
|
My pleasure.
I hear McDonalds is hiring... maybe it'd be more appropriate for you.
|
|
|
|
|
If this is so easy for you, why don't you do it, big Lunatic head?
|
|
|
|
|
Waldemar Ork wrote: If this is so easy for you, why don't you do it, big Lunatic head?
Because it's not his job to do your homework, it's your job.
|
|
|
|
|
Why the hell should I? You can't be bothered to make any effort beyond cutting and pasting your homework problem into the forum; you're too lazy or stupid to make even the feeblest of attempts on your own. So why the hell should I?

|
|
|
|
|
Because that's you who says 'I'm clever', that's obvious at the first sight. I personally might be even called stupid, because programming isn't what I like most. Just have to do it. But I can assure you I'm not a stupid person at all. I can do lots of things and I'm not a snob. If you don't want to do it, don't do it. Just show off replying to other posts in the same way. Good luck!
|
|
|
|
|
Right now you've got two separate main() functions. How about renaming each of those to something more appropriate, and then create a new main() function that calls each of them?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i need information about online courses/ training for vc++ (basic and advanced).
can u please provide me.
thanks & regards
|
|
|
|
|