|
Is this code OK!
Node* Nodes[101];
refNodes& getNodes()
{
for(int i=1;i<=100; ++i)
{
Nodes[i] = new Node();
}
return Nodes;
}
Thanks!
Yonggoo
|
|
|
|
|
Yes, but you've failed to initialize Nodes[0] . The preferred style is:
for (int i = 0; i < 101; ++i)
...
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
No, since you can't convert Node*[101] to Node&.
You could return Nodes[101] as a Node**. I'm not sure how you would return it as a reference or why you would bother.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Joe Woodbury wrote: Because a pointer can be NULL. A reference means the object has to exist (of course, that object may not be fully initialized, but it does mean you don't have to worry about a NULL pointer.)
That is a red herring...
struct A {
int a;
};
void func1(A& r)
{
printf("r.a = %d\n", r.a);
}
void func2(A* p)
{
func(*p);
}
...
A* p = 0;
func2(p); Guess where it'll blow up on you in virtually all C++ compilers? References in C++ are not safer than pointers. It's just an illusion...
|
|
|
|
|
Joergen Sigvardsson wrote: void func2(A* p)
{
func(*p);
}
The only reason it blows up is because you are dereferencing a NULL pointer, not because references are not safe. And one wonders why so many products have stupid warning labels; to prevent them from being used in ways they were not intended to be used.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
PJ Arends wrote: The only reason it blows up is because you are dereferencing a NULL pointer, not because references are not safe.
My point is that you can't trust a reference to be always valid, as many people suggest.
--
Fun for the whole family - except grandma and grandpa
|
|
|
|
|
Yonggoo wrote: Node& Nodes[100];
? = new Node();
I don't think you can have an array of references
Yonggoo wrote: Node* Nodes[101];
refNodes& getNodes()
{
for(int i=1;i<=100; ++i)
{
Nodes[i] = new Node();
}
return Nodes;
}
return Nodes; is returning a Node**. Is that what a refNodes& is?
Mark
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens. It's a dumb question... skip it."
|
|
|
|
|
Basically what I'm trying to do is open up a file, check to see if everything is ok, and then get a line from the file and pop up a box with the text from the getline(). Then I got all these errors upon compiling. The line which the errors are pointing to is marked with a smilie. I don't really know what to do with them so I'd appreciate any help. The code:
bool CRatiosNewSearchDialog::LoadExpressionsFile(CString Path)
{
bool Success = true;
CString FirstLineText = "";
ifstream expressionFInput(Path);
if(expressionFInput.fail())
{
MessageBox("Could not load expressions file: " + (CString)Path, "Error", MB_ICONWARNING);
Success = false;
}
else if(EOF == expressionFInput.peek())
{
MessageBox("Expressions file is empty: " + (CString)Path, "Error", MB_ICONWARNING);
Success = false;
}
else
{
:^)getline(expressionFInput, FirstLineText, '\n');
MessageBox(FirstLineText, "First Line", MB_OK);
}
return Success;
}
</code>
These are the errors:
\Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : expects 2 arguments - 3 provided
\Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::ifstream'
\Work\Copy of Ratios_2006\Ratios\ratios_searchdialogs.cpp(58): error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Ax> &' from 'CString'
I'd appreciate any help. -John
|
|
|
|
|
CoffeeAddict19 wrote: expects 2 arguments - 3 provided
This is the answer. Look at the first error message.
|
|
|
|
|
getline(expressionFInput, FirstLineText);
same error. :/ It doesn't care whether I have 3 arguments or two. Go figure.
|
|
|
|
|
You've provided 2 arguments. Does the compiler say that you have provided 3??? Strange thing. Have you rebuilt the project or just proper cpp?
|
|
|
|
|
Anyway if the error occurs after your change it means tha you have used wrong arguments check 2 another errors from your first post.
Try to use istream instead of ifstream and string instead of CString
|
|
|
|
|
I gave in and did it with a string...works fine. Thanks. Still annoys me the though. Has anyone written a defenitive guide on how all of these character and string formats work together? Has anyone done a performance analysis on the different types of strings and their functions to see what works fastest in what appication? Seems like someone could write a book on it.
|
|
|
|
|
Yes. I rebuilt it.
I hate Microsoft.
e:\Work\Ratios\ratios_searchdialogs.cpp(61): error C2780: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem)' : expects 3 arguments - 2 provided
|
|
|
|
|
--------------------------------------------------------------------------------
I'll preface this by saying, I'm pretty new to C++ and Windows programming, I've mostly done embedded systems in C and assembler. This is probably a really simple thing, I just can't seem to get it done.
I'm trying to use the Static LED control http://www.codeguru.com/Cpp/controls/controls/article.php/c2351[^] in a Dialog based application.
On the main dialog, it's no problem, works just like a champ. However, I have a popup dialog that I want to put some detailed information on, and I can't seem to get it working there. I have some floating point values that I can simply update the class variables to set their displayed values, but the LED CLed class isn't so simple. How do I access this control on the popup dialog, what am I missing?
|
|
|
|
|
gunrunnerjohn wrote: How do I access this control on the popup dialog...
From where?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Well, I was trying to set the LED controls from the main dialog that launched the popup dialog itself. Is there a way to add the code to the popup dialog, I didn't see any obvious way. I don't want to have to click any buttons in the popup to make the values appear, I want them there when the dialog opens. The data I need to actually set the LED status is in some global variables, so I can get to them from anywhere.
-- modified at 21:30 Friday 23rd February, 2007
|
|
|
|
|
Perhaps I'm making this too difficult. Is there a way to add a function to the popup dialog that runs on initialization? That would do what I'm trying to do.
|
|
|
|
|
Never mind.
I was making it too difficult, all I need to do is use the OnInitDialog() to do the initialization. I know there must be an easy way...
|
|
|
|
|
Hi, I'm not sure where this questions belongs, so I posted it in the C# and C++ boards.
My goal is to create a C# COM Object that will act be a source for an unmanaged C++ sink. I followed the guide that I found at http://support.microsoft.com/kb/313891 to create the C# object, but I was unable to get callbacks from the resulting .NET component with my C++ client. I have found that I can get the C++ client to work if I have a "SetCallbackFunction( IntPtr callbackFunctionPointer )" method in the C# code, but this solution is not acceptable for my project. Is there any way that I can get events working correctly using the technique described in the link I provided earlier? If not, is there any way to fire an event in C# and have the C++ handle it without a set function method? I'm used to the ConnectionPoint stuff for COM objects, but that doesn't seem to apply here. Thanks for the help.
|
|
|
|
|
please can someone help me?
I wrote a program about 1year ago in C++ Builder it was supposed to draw frames onto a Bitmap control, but I need now to save this frames as video file. I don't know how to store frames as video file please can someone tell me how to do that? frames are Black&White and 50FPS coming from a video capture card on PCI (if it matters)
p.s Sorry for bad English
|
|
|
|
|
Hello,
I'm using the source from the THIS ARTICLE:
http://www.codeproject.com/dialog/cdialogsk.asp[^]
but when I run this code:
.h file:
http://pastebin.com/887372[^]
.cpp file:
http://pastebin.com/887377[^]
I'v got the following errors:
<br />
<br />
1>DOLPHIN_MFC.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall CDialogSK::~CDialogSK(void)" (__imp_??1CDialogSK@@UAE@XZ) referenced in function "public: virtual __thiscall CDOLPHIN_MFCDlg::~CDOLPHIN_MFCDlg(void)" (??1CDOLPHIN_MFCDlg@@UAE@XZ)<br />
1>DOLPHIN_MFCDlg.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall CDialogSK::~CDialogSK(void)" (__imp_??1CDialogSK@@UAE@XZ)<br />
1>DOLPHIN_MFCDlg.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall CDialogSK::CDialogSK(unsigned int,class CWnd *)" (__imp_??0CDialogSK@@QAE@IPAVCWnd@@@Z) referenced in function "public: __thiscall CDOLPHIN_MFCDlg::CDOLPHIN_MFCDlg(class CWnd *)" (??0CDOLPHIN_MFCDlg@@QAE@PAVCWnd@@@Z)<br />
1>DOLPHIN_MFCDlg.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: virtual void __thiscall CDialogSK::DoDataExchange(class CDataExchange *)" (__imp_?DoDataExchange@CDialogSK@@MAEXPAVCDataExchange@@@Z) referenced in function "protected: virtual void __thiscall CDOLPHIN_MFCDlg::DoDataExchange(class CDataExchange *)" (?DoDataExchange@CDOLPHIN_MFCDlg@@MAEXPAVCDataExchange@@@Z)<br />
1>DOLPHIN_MFCDlg.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: static struct AFX_MSGMAP const * __stdcall CDialogSK::GetThisMessageMap(void)" (__imp_?GetThisMessageMap@CDialogSK@@KGPBUAFX_MSGMAP@@XZ) referenced in function "protected: static struct AFX_MSGMAP const * __stdcall CDOLPHIN_MFCDlg::GetThisMessageMap(void)" (?GetThisMessageMap@CDOLPHIN_MFCDlg@@KGPBUAFX_MSGMAP@@XZ)<br />
1>DOLPHIN_MFCDlg.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) protected: virtual int __thiscall CDialogSK::OnInitDialog(void)" (__imp_?OnInitDialog@CDialogSK@@MAEHXZ) referenced in function "protected: virtual int __thiscall CDOLPHIN_MFCDlg::OnInitDialog(void)" (?OnInitDialog@CDOLPHIN_MFCDlg@@MAEHXZ)<br />
1>C:\Documents and Settings\Semion Naidis\My Documents\Visual Studio 2005\Projects\DOLPHIN_MFC\Debug\DOLPHIN_MFC.exe : fatal error LNK1120: 5 unresolved externals<br />
Why, And how can I solve them?
***Another little ask-Do you know any classes with a button that looks like switchs with On And OFF?
You know this metal switch...
SnaidiS(Semion)
|
|
|
|
|
Anybody please?
SnaidiS(Semion)
|
|
|
|
|
They are all linker errors and from the looks of it, you are missing the object code that
implements the CDialogSK class. If the sample code was provided as a library then you can link to
that (add the library to your project). If the sample code is in source form then you could add
the source files to your project.
Mark
"Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot?
Of course you don't, no one does. It never happens. It's a dumb question... skip it."
|
|
|
|
|
I added the files but maybe I'm adding it in a wrong way, can you please give me the correct steps to add .h and .cpp files to my project?
SnaidiS(Semion)
|
|
|
|