|
A const string reference is being passed just as a string to another proc.The code crashes after the call a_proc(). Please give your inputs
Imp::Reset(const string& res_str, const bool& b)
{
a_proc(res_str);
a_get();
}
Imp::a_proc(string res_str)
{
//res_str is just validated
}
|
|
|
|
|
Nothing wrong with passing the string a const reference, it's not the cause of the crash. Use your debugger to see where the crash occurs precisely and for what reason.
|
|
|
|
|
The Issue now is passing the variable that was retreived as a const string& is passed to another proc as just a string(passing by value). Any comments on this.
sorry, I don't have a debugger.
|
|
|
|
|
As I said, there's nothing wrong with passing a string by const reference and it won't make any different. You are focusing on the wrong problem and should try to find the real cause of the problem.
apphia_j_79 wrote: sorry, I don't have a debugger.
With which IDE are you coding ? Developping without a debugger is like cooking without knives
|
|
|
|
|
Probably you should post the actual code to get better help.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
And while you're thinking of posting your code consider why you're passing the string by value to a_proc and using a const reference to bool in Reset.
The first one I can see a point for if you were going to copy the string anyway to mangle it but the const bool &b thing doesn't make a lot of sense.
Oh, hang on, you're not casting it to something else in the function to modify it are you?
Ash
|
|
|
|
|
You should check the string before sending it to Reset, or the object owning the string. Taking its reference might be ok even if the instance no longer exists, but once you dereference it, you might get an access violation.
Typically, problems like this occurs if your string is a member variable in an instance you have deleted (or is null).
class A
{
string s;
public:
void method() { Reset(s); }
};
A *a = nullptr;
a->method();
The above code will work when Reset() takes a reference to the string, but not if it accesses its value, which a call-by-value does.
|
|
|
|
|
Hi!
I got the following while compiling my program.
d:\test\test\nrp2dpictureflow.cpp(90) : error C2782: 'const T &irr::core::min_(const T &,const T &,const T &)' : template parameter 'T' is ambiguous
1> e:\irrlicht-1.7.1\include\irrmath.h(123) : see declaration of 'irr::core::min_'
1> could be 'irr::u32'
1> or 'int'
1>d:\test\test\nrp2dpictureflow.cpp(90) : error C2780: 'const T &irr::core::min_(const T &,const T &)' : expects 2 arguments - 3 provided
1> e:\irrlicht-1.7.1\include\irrmath.h(116) : see declaration of 'irr::core::min_'
Th function min_ is defined as follows:
template<class T>
inline const T& min_(const T& a, const T& b)
{
return a < b ? a : b;
}
template<class T>
inline const T& min_(const T& a, const T& b, const T& c)
{
return a < b ? min_(a, c) : min_(b, c);
}
Why the compiler expects the third value? What value do I have to pass as third argument to min_ ?
|
|
|
|
|
And what is your code actually ?
|
|
|
|
|
Check the way you're calling the function. The parameter you pass must have all the same type (or decade implicitly all into a same common type). If -for example- you pass an int and a float the compiler cannot decide which has to be converted into the other.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
is there any API which i can import a registry file in the registry editor? moreover in my registry file is a key which need full control permission for everyone in HKEY_LOCAL_MACHINE, how can i get this through source?!
thanks
|
|
|
|
|
|
thanks a lot for your attention, but i want to use just one function to import file to registery editor, something like "import" option in "file" menu of registry editor since there is lots of keys in HKEY_CLASSES_ROOT, HKEY_CURRENT_USER and HKE_LOCAL_MACHINE in this file, and i don't want to import them separately.
moreover be conscious please, i have to use MFC i'm NOT allowed to use .net framework.
thanks for your help
|
|
|
|
|
How to show the time value in edit control which is attached with spin control. I also need increase or decrease the time value with the help of Spin control..
Please help me..
Thanks..
|
|
|
|
|
Use one of the time[^] functions to obtain a string with the current time which you can display in the edit box. Use the spinner controls to adjust the values (based on selected characters) up or down and adjust your time value as necessary.
It's time for a new signature.
|
|
|
|
|
can u please provide me some sample code as I m very new in MFC..
Thanks..
|
|
|
|
|
The link I posted for the time functions should explain all you need to know about obtaining time values as strings. Take a look also at the CSpinButtonCtrl[^], it has links to sample code that should help. You will find similar pages for all the other MFC classes.
It's time for a new signature.
|
|
|
|
|
Why don't use CDateTimeCtrl , which encapsulates the functionality of a date and time picker control. If its set to DTS_TIMEFORMAT it has a spin control and displays formatted time.
|
|
|
|
|
Hi
I want to use MS Excell in VC++ program for recording and plotting data.
Should I use CRecordSet Class or else.
If yes, can I have some example program for it?
Regards
|
|
|
|
|
As far as I know, the CRecordset class is used when you are working with databases.
In your case, you have to use Excell automation, search on CP and google for it and you'll find a lot of tutorials.
QSMZ wrote: I want to use MS Excell in VC++ program for recording and plotting data.
You mean that your program should create an excell file and write data in it then create a chart in the excell file ? If yes, I think this should be feasible through automation.
|
|
|
|
|
QSMZ wrote: I want to use MS Excell in VC++ program for recording and plotting data.
I'm not really clear on what you mean.
Perhaps you would benefit from writing a DLL that you use from Excel for "data recording" depending on the where you get the "data" from.
If you only want Excel for presentation reasons you may record and plot the data in your own application, but save it to an Excel file and draw charts in it using automation as Cédric said.
I've done this about five years ago, but unfortunately that means I don't have any source code to give away and I've forgotten the details.
However, it's not really that hard, just search for Excel and automation and you'll get a lot of useful results.
One tip I remember though, use multidimensional safearrays for writing the data into the Excel sheet if you have a lot of data. I had about 10MB and writing it cell by cell took about 40 minutes. Using a multidimensional safearray it only took a couple of seconds.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
search
BasicExcel on codeproject
|
|
|
|
|
A Simple search of code project yields a number of jewels. ^[]
there are a lot of things to consider when you begin trying to use windows office automation not the least of which C++ isn't the "best choice". VB ultimately is a much better choice for this type of task(native language for excel). Also for deployment will the target users all have office? will they have the "right" version of office? Do you really need to write a full blown app or will VB scripting do the job?
Excel objects are setup just like the in the program books, pages, range and cell.
|
|
|
|
|
Hi!
how do i convert a date to struct tm?
i want to get day of week for this date.
this code has a run time error:
int yy = 2010;
int mm = 07;
int dd = 12;
struct tm tt;
time_t t;
yy -= 1900;
tt.tm_mon = mm;
tt.tm_year = yy;
tt.tm_mday = dd;
t = mktime(&tt);
struct tm *tt2 = localtime(&t);
int ii = tt2->tm_wday;
please help me.
Zo.Naderi-Iran
|
|
|
|
|
zon_cpp wrote: time_t t;
time_t t = {0};
i.e. never, never, never forget variable initialization.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|