|
fearless_ wrote: directx 9 I have not used DirectX, but I have used plenty of other Windows' functions that use structures, arrays of structures, and even arrays of structures that contain other unstructured structures. In the latter case, the presence or absence of certain items depends on settings elsewhere.
|
|
|
|
|
You have a vast experience, I appreciate all your help.
|
|
|
|
|
fearless_ wrote: You have a vast experience ~Far from it, what I don't know would fill many books.
But given that I know some stuff, I am happy to help.
|
|
|
|
|
So is this pointer a save of the physical address of the real thing or just an artifice done by the compiler which matches the data behind the scenes to achieve the desired result?
|
|
|
|
|
It is the actual address in the pointer. In that way you can address any array, or any structure just by passing the real address to the function.
void myFunc(char* someData, int length)
{
for (int i = 0; i < length; ++i)
{
char c = toUpper(someData[i]);
someData[i] = c; }
}
You can now call that function with any array of any length and get it converted.
In every case the function receives the physical address of the array and accesses each
character by using the index value i , where 0 <= i < length .
|
|
|
|
|
|
You can do either of these, depending on what you want to do:
void process_Carray(int const* values, int n_values);
template <int size> void process_C11array(std::array<int,size> const& values);
void process_vector(std::vector<int> const& values);
void process_Carray(int* values, int n_values);
template <int size> void process_C11array(std::array<int,size>& values);
void process_vector(std::vector<int>& values);
The first variant is deprecated in C++, it should be restricted to pure C code.
The second variant is useful if you know the size of your arrays at compile time (and it's always the same)
The third variant is the most flexible as you don't need to know the array size, and you can even add more values within your function if you desire.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
thanks, I also understand `defensive programming` now.
|
|
|
|
|
Just as a conclusion to everything that has been said in this thread, if you want to pass an array as argument you have to declare it as pointer in the function definition.
|
|
|
|
|
How could you not?
A C "array" IS a pointer to the start of it. There is nothing more to it.
Stop thinking of C as a high level language. It is a CPU independent assembly language.
|
|
|
|
|
Error in line :
CString sURL = URL->bstrVal;
//bstrVal is BSTR TagVariant
Error is
error C2440: 'initializing': cannot convert from 'BSTR' to 'ATL::CStringT<char,strtraitmfc_dll<char,atl::chtraitscrt<_chartype>>>'
1> with
1> [
1> _CharType=char
1> ]
1>note: Constructor for class 'ATL::CStringT<char,strtraitmfc_dll<char,atl::chtraitscrt<_chartype>>>' is declared 'explicit'
1> with
1> [
1> _CharType=char
1> ]
|
|
|
|
|
try
CString sURL = (LPCTSTR)(_bstr_t)URL->bstrVal;
|
|
|
|
|
Did you preserve the project Character Set value in the migration process?
Quote: _CharType=char is an hint a "Not Set" or "Use Multi-Byte Character Set" is selected, while "Use Unicode Character Set" would be possiby more appropriate.
|
|
|
|
|
Migrated application from VS2010 to VS2017.
application is looking for
errorStruct.lib file.. and it is not available on my system.
Is this VS2017 file which is missing?
Guide me on this.
|
|
|
|
|
Check your project to see where it is being referenced from.
|
|
|
|
|
Code is here
CSiBatchJobMigrationDlg::CSiBatchJobMigrationDlg(CWnd* pParent )
: CDialog(CSiBatchJobMigrationDlg::IDD, pParent)
{
m_sDatabase = _T("");
m_leaveDevRow = TRUE;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pMenu = new CMenu;
}
Giving me error in below line
SiBatchJobUpdateDlg updateDlg = SiBatchJobUpdateDlg(this);
Code was working fine in VS2010 but getting this error after migration from vs2010 to vs2017
|
|
|
|
|
Hello,
I suppose that this should be better :
SiBatchJobUpdateDlg updateDlg(this);
|
|
|
|
|
|
There are a total of P levels. For any level p, there are Jp nodes. Any two nodes on the same level are not connected. And the unidirectional path weight between any two nodes Ai and Bj is D(i,j).
What is the shortest distance required from the first layer to the Pth layer?
(** Note that P is generally large and it is not recommended to traverse all possible situations **)
If this problem is abstracted as a graph, then what is actually required is the shortest path from the first layer to the last layer of a fully connected network.
What I have tried:
Use deep search, Dijkstra algorithm, Floydw algorithm, etc. to search the shortest path from all J1 nodes in the first layer to the last layer in turn, and select the minimum value from the J1 values.
What I want to know is if there is a simpler algorithm to solve this problem?
|
|
|
|
|
If I understand this correctly, you're looking for a unidirectional path from the first layer to the pth layer, a path that includes each layer only once.
I would start with the second layer. Assign each node its shortest distance from the first layer, and record the first layer node whose edge was selected. Then proceed through each layer in the same way: for each node, find its shortest distance from the nodes in the previous layer (the current weight of a previous node plus its edge to the current layer). Eventually you will find the shortest distances to nodes in the pth layer, and thus the shortest path to that layer.
|
|
|
|
|
Simulated Annealing[^] could be effective. I don't know if it belongs to the 'simple algorithm' category.
|
|
|
|
|
Unfortunately it can in general not guarantee that it will find the global optimum. You can find a good guess very quickly, or you can slow the annealing to the pace of continental drifts and have a higher chance to find the correct answer, but you can never be 100% sure unless you test all options, i. e. brute force.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
You are right, of course.
If the problem needs an exact solution, Simulated Annealing is not the right algorithm.
|
|
|
|
|
Simpler than Dijkstra? Seriously? Dijkstra is the obvious choice. You may be able to find a faster algorithm, but not a simpler one, unless you use brute force.
P.S.: I wasn't familiar with the Floyd-Warshall algorithm[^] (assuming that is what you were referring to). It seems like it is simply a specialiced version of Dijkstra applied to a weighted graph. Sounds like it's a perfect fit for this problem.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
modified 27-Mar-20 4:57am.
|
|
|
|
|
Write and test the following function that attempts to remove all occurrences of an item from an array:
intremove(int a[], int& n, int x)
The function searches the first n elements of the array a for the item x. If an x is found, it is removed, all the elements above that position are shifted down, the
array size n is decremented. This is repeated until all occurrences of x in the array are removed and then the total number of elements removed is returned. If x is not
.Write your own Car class. The class data should include:
I. make (using an array of char),
II. year,
III. petrol,
IV. tankSize,
V. mpg (miles per gallon),
VI. owner (using an array of char).
The functions should include:
I. display,
II. fillPetrol: pass number of gallons as a parameter and return gallons actually input (before full),
III. drive: pass distance as a parameter and return distance actually travelled (stopping if empty),
IV. changeOwner (passing new name as a parameter).
V. You should also have two constructors (one with and one without parameters) and any other functions needed, such as full() and empty(). (Should these 2 functions be public or private?)
VI. Put code in the constructors to show when each is called (cout<< "Constructor X called";).
VII. Write a program to create and use a Car object, making sure it calls all the public functions.
|
|
|
|