|
Sauce! wrote: *theArray[i][j]
why the * - the dereference is implied when you use array indexing.
Sauce! wrote: Can anyone link me to a good article that explains why template functions must be defined in the header
It's basically because when you instantiate a template, that's when the compiler compiles the template class methods. All the compiler can see at that point is what's in the header file.
This page[^] has a reasonable explanation.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: why the * - the dereference is implied when you use array indexing.
Error 1 error C2440: '=' : cannot convert from 'int' to 'int *' c:\users\bryce\documents\visual studio 2008\projects\array2d\array2d\main.cpp 20
visual studio tells me otherwise
The real reason is that theArray is a pointer to an object of type Array2D . Re-read the code and it makes sense.
You were helpful though, I recall that the [] operator has a higher precedence than * . Adding brackets like fixes it... to a point. I'm now able to move through a few more elements of the array without crashing, but I'll have to do more debugging before I can find out why. Most likely [i] and [j] need to be swapped.
The two lines you were talking about should become (*theArray)[i][j] = temp; and temp = (*theArray)[i][j];
Thanks for the help, I'll edit this when I know more information.
edit: as suspected, j and i were simply swapped with each other Code works 100% now
modified on Saturday, April 4, 2009 2:42 AM
|
|
|
|
|
Sauce! wrote: Error 1 error C2440: '=' : cannot convert from 'int' to 'int *' c:\users\bryce\documents\visual studio 2008\projects\array2d\array2d\main.cpp 20
visual studio tells me otherwise
The real reason is that theArray is a pointer to an object of type Array2D. Re-read the code and it makes sense.
So it is
I rarely use unmanaged (in the smart pointer/RAII sense of managed, not the .NET sense of managed!) pointers, especially in a case like that, when the object contains pointers to allocated items. I'd just code it like this:
Array2D<int> theArray(width, height);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
The reason I've done it this way is because Array2D (not in my test project here, but in the project it was intended for) is used as a member variable for a user-defined class. Array2D expects a width and height as arguments to the constructor. Consider:
class someclass
{
public:
someclass();
~someclass();
private:
Array2D<int> *myArray;
};
someclass::someclass(UINT width, UINT height)
{
myArray = new Array2D<int>(width, height);
}
someclass::~someclass()
{
delete myArray;
}
alternatively...
class someclass
{
public:
someclass(UINT width, UINT height):myArray<int>(width)(height);
~someclass();
private:
Array2D<int> myArray;
};
someclass::~someclass()
{
}
I'm really not a fan of the second snippet. It just comes down to preference really. Unfortunately that means I have to pay the price and place brackets around the dereference operator to override operator precedence like so; (*myArray)[x][y]
|
|
|
|
|
IMO, just keep one array of Width*Height and have an accessor function with row and column as parameter and just return the item at the appropriate position.
Something like that.
T* = pArray[column * Height + row];
This signature was proudly tested on animals.
|
|
|
|
|
Reading the answers, your problem has been solved.
I just wanted to thank you for possibly the best written question I've seen! Even with a diagram...
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
I figure if I don't put any effort in, then my chances of getting a decent answer are pretty low. I try my best to offset some of the terribly-worded questions you see around here. Not to mention the terrible questions!
Thanks to everyone for the help
|
|
|
|
|
Hi,
I need to create an Executable for my MFC AppWizard(dll) project. This is to debug my program. This is a new program and has no idée how to create an Executable. Other existing programs are easy to debug as they have an .exe file link to the .dll. Please, any help would be appreciated.
|
|
|
|
|
Your query is confusing. My best guess is that you're writing a dynamic link library and you do not know how to debug it.
If I'm right, then just try executing the library from within the IDE like you would execute a normal .exe (F5, Ctrl+F5) and the IDE must ask the executable that would be loading this DLL and it would run that executable.
As soon as that executable executes code from within your DLL, the debugger will get activated and you can debug your DLL (break points, you know).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Thx for the reply. Yes I don’t know how to debug it, the thing is when I hit (F5 or Ctrl+F5) a box pops up asking for the Executable file name. It gives me 3 options: (1) Browse, (2) AxtiveX Control Test Container and (3) Default Web Container. All my other projects that I am working on were pre-existing and they have an Executable. I don’t know how they where created?
|
|
|
|
|
It is asking for an executable because you are working on a library and the library cannot execute on its own. The library will be, in practice, loaded by another executable (or even another library). Just use the browse option and choose the executable that will be loading and using this library. When the library code is executed, the debugger will be activated if you have breakpoints in your library code.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Sorry, but i am confused. Theres no where any .exe to be found. I'm not sure what you ment by :
"Just use the browse option and choose the executable that will be loading and using this library"
Don't i need to create the .exe?
|
|
|
|
|
blokkies wrote: Don't i need to create the .exe?
If you don't have any exe that uses your dll yet, yes you have to create one. You dll can't be used alone, it should be loaded by an executable.
But what is your problem exactly ? Because if you are able to create a dll, creating an executable shouldn't be too difficult...
|
|
|
|
|
my problem is that I am not able to debug my program? When 'n hit F5 it asks me for an executable. When 'n go build, the only option is to build the .dll. Other program that i am working on has an .exe that they use to debug the code. How do I create an .exe for this new project?
Please beer in mind that i am not a C++ programmer but SAS,RPG and SQL.
|
|
|
|
|
blokkies wrote: How do I create an .exe for this new project?
In the same way that you created the DLL, except that you select Application instead of DLL (or Library). What version of VS are you using?
"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 am using Visual C++ 6.0. I created only one MFC AppWizard(dll) project. On the Build option i can only choose Build XXX.dll (F7).
Thanks.
|
|
|
|
|
blokkies wrote: I am using Visual C++ 6.0.
File --> New --> Projects
"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
|
|
|
|
|
blokkies wrote: Please beer in mind that i am not a C++ programmer but SAS,RPG and SQL.
Then it's gonna be really complicated to explain what you have to do. Because you'll need not only to create the executable but also add some code inside it to load the dll and call the functions you want to debug.
But if you are not a C++ programmer, why are you developping a DLL ? It seems a bit crazy that you start with that instead of learning the basis (learn the language, create a simple app, ...)
|
|
|
|
|
I agree, but i am just the employee. I have been doing maintenance on existing C++ systems with little problems. Maybe that’s why. But it is something different to start from scratch. I really wanted to get this right.
Thanks for the help.
|
|
|
|
|
Can you just tell me how do i create the Executable?
|
|
|
|
|
You've already been told...at least twice. What more do you require? If you are not going to heed our suggestions, stop asking for help.
"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
|
|
|
|
|
People already told you how to do that (David for instance). But, then ? You will end up an executable that doesn't do anything with the dll and there's no point in that. You will need to add code to load the dll and call some functions but in order for us to help you, you'll need to learn at least the basics of C++ and visual studio.
You think creating an executable is just a matter of clicking there and there and BAM, magically your executable doing what you want is created ?
|
|
|
|
|
To be fair, he might be working with a VB executable
|
|
|
|
|
It depends because it could even complicate things a lot (for instance if he needs to pass strings or objects to a dll function).
|
|
|
|
|
Cedric Moonen wrote: You think creating an executable is just a matter of clicking there and there and BAM, magically your executable doing what you want is created ?
That's what my (non-programming) colleagues tell me!
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|