|
7. Given the class definition
class A
{
public:
//constructors
// other members
private:
int x;
int y;
};
Give declarations of operator functions for each of the following ways to overload operator+ you must state where the declaration goes, whether within the class in the public or private section or outside the class. The operator + may be overloaded
a. as friend function
b. as member function
c. as non-friend, non-member function
I have exam from next week and this one of the ques in sample paper .please help me to solve it.
|
|
|
|
|
If it's really urgent, please post it on the correct board[^].
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
charusood wrote: please help me to solve it
No. You should have been paying attention in class.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hello again!
I got an "undefined reference" again, but I don´t know why!
Maybe someone could help me!
The compile-command is:
g++ -o headerblub.exe main.cpp header.cpp blub.cpp
Here´s the code:
main.cpp:
#include "header.h"
int main(int argc, char **argv)
{
HeaderTest h;
h.headerH();
return 0;
}
header.h:
#ifndef HEADER_H
#define HEADER_H
namespace Headerns
{
#include "blub.h"
}
class HeaderTest
{
public:
void headerH();
};
#endif
header.cpp:
#include "header.h"
void HeaderTest::headerH()
{
Headerns::blub();
}
blub.h:
#ifndef BLUB_H
#define BLUB_H
void blub();
#endif
blub.cpp:
#include "blub.h"
#include <iostream>
using namespace std;
void blub()
{
cout << "Hurra" << endl;
}
</iostream>
Thanks a lot!
Stefan
|
|
|
|
|
First, you're on the wrong board.
Visual C++/MFC[^] is for non-managed C++ questions.
Second, why would you #include a file within a different namespace?
I don't have g++ so I can't try your code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
oh, I´m sorry. I´m new here and I don´t have an overview about the board yet.
I have to include the file in a namespace for a project I´m working on. But I found out the sollution by changing the blub.cpp into:
#include "header.h"
#include <iostream>
void Headerns::blub()
{
std::cout << "Hurra" << std::endl;
}</iostream>
|
|
|
|
|
Here's what I'm talking about...
This makes usage difficult and error prone:
namespace Headerns
{
#include "blub.h"
}
Why should you have to always remember to wrap the #include in
a namespace?
Why not do this instead:
#ifndef BLUB_H
#define BLUB_H
namespace Headerns
{
void blub();
}
#endif
#include "blub.h"
#include
using namespace std;
void blub()
{
cout << "Hurra" << endl;
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am using Visual C++ NET 2005,
I have create one form called "User".
After some handling, in my Solution Explorer, I don't see again my Designer interface (User.h[design]).
But User.h and User.cpp files exist.
How can I view again My design Interface ?
I don't Understand This problem
modified on Wednesday, October 8, 2008 1:38 AM
|
|
|
|
|
Have you tried closing the designer, recompiling your code, and then re-opening the designer? If this doesn't work, could you provide some more details? When you try to view the designer, do you get any particular error messages?
|
|
|
|
|
I have do it: to close the program ad to open again, when I click on design interface I have I red cross with this message(it is not exactly the same words but the same idea ):
Your design interface can not be open due to error. To fix it your rebuild the project or correct codes.
Why in this version, we have this kind of problem ?
|
|
|
|
|
your form class should be first class in the namespace, if there is other class before your form class, move that class.
Nigah M Manzoor
|
|
|
|
|
This is probably far too late, but wanted to add this for the record - I had a similar problem and solved it by clicking on the h file in question, look in the 'properties'window on the right and set the 'File Type' to 'Form' (somehow it had been reset to 'h file'
|
|
|
|
|
I'm writing a transformfilter with 1 input and 2 output pins. I've derived my Transformfilter from CBaseFilter and the pins from CBaseInputPin and CBaseOutputPin. I'm pretty sure my Filter works because if I've only 1 Pin the sample process how it should, but if I add the second output pin the video stops with the first sample on one window a shows nothing on the second window.
When I debug the second time i call GetDeliveryBuffer i get the error code -2147220975.
Here is what i did in the method Receive:
hr = pOutputPin1->GetDeliveryBuffer(&pOutSample1, NULL, NULL, 0);
hr = Copy(pSample, pOutSample1);
hr = Transform1(pSample, pOutSample1);
hr = pOutputPin1->Deliver(pOutSample1);
pOutSample1->Release();
hr = pOutputPin2->GetDeliveryBuffer(&pOutSample2, NULL, NULL, 0);
hr = Copy(pSample, pOutSample2);
hr = Transform2(pSample, pOutSample2);
hr = pOutputPin2->Deliver(pOutSample2);
pOutSample2->Release();
What am i doing wrong?
|
|
|
|
|
You may get an answer, but generally DirectShow questions
don't get much love here.
I know there's a couple MVPs that really know this stuff....you can
find them here:
MSDN DirectX.Video Newsgroup[^]
Hope that helps!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi itchy,
I see you're getting a little help over on the other board.
I was just thinking, if you're delivering the same samples to both
output pins, why not just use a single output pin into an infinite tee filter?
Just a random thought,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yeah I'm getting help, but up until now nothing is working.
I know I could use the inftee filter, but I don't want that because I'm making changes to both samples. If I use inftee filter I need to write 2 filters.
Besides its good practice, if it would work .
Thanks by the way for redirecting me.
|
|
|
|
|
|
Please post on the Visual C++/MFC board[^].
This board is for Managed C++/CLI questions only.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a Managed C++ Windows Forms program that I'm compiling in Visual Studio 2003. When I try to run it, it tells me "Program too big to fit in memory" in a command prompt.
Does anyone know why it would even pop up with a command prompt window when this is a Windows application? Secondly, why would I get this error? Sources from google tell me that usually, this has to do with a corrupt installer issue, but this is not an installer at all.
Thanks.
|
|
|
|
|
I think I might've found the issue. I believe it lies with trying to reference an unmanaged lib (not compiled with managed extensions in C++), from a project that is compiled into a managed executable (managed extensions enabled). From what I've read, it seems to me (so far) that the only way to do this is to use a .dll and PInvoke, but is there any way to simply use a .lib?
|
|
|
|
|
The lib should work fine. C++/CLI lets you call code in static and
dynamic libraries without p/invoke.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
Thanks for the info, however, here's the problem. The first time I do a build, it always fails with a LNK1000 error where essentially, VC7's link.exe throws some kind of exception. If I try to build it again, it succeeds. Always. The only problem is, that the generated executable is invalid. At first, I couldn't figure out what was wrong. Then, because I suspected some kind of dependency issue, I ran depends.exe on the generated executable, and it told me that the PE header was invalid (or something to that effect). Then, that was where I suspected the managed/unmanaged stuff.
I should also note that I have a solution of 3 projects, 1 of which is the executable (managed), 1 of which is a static library (managed), 1 of which is a static library (unmanaged). If I remove the unmanaged static library from its reference list or dependency chain, building the executable complains about linker errors (as expected, since I have not defined the symbols). As soon as I add the unmanaged static library, I get the LNK1000.
|
|
|
|
|
Cyrilix wrote: 1 of which is a static library (managed)
I'm not sure how well that's going to work, nor can I find any
solid confirmation one way or the other.
Binding of managed types in a library is done at the assembly level.
I'm not sure how well the linker's going to handle that.
A managed class library (DLL) is the appropriate way to make a managed
library (even if it has native code in it as well).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Well, the way it works is that I have a managed static lib that contains my __gc classes. Then, I have an unmanaged static lib depending on and using the managed static lib that contains regular (non __gc) classes, which is sort of my interface to the native world. I've been able to use this interface with other classes from native code without problem. Then, I have a Winforms app which depends on that native interface. Now that I think of this, it doesn't really make sense as to why I'm doing it this way. I'm sort of going Managed->Unmanaged->Managed... might as well see if I can cut out the middle layer.
|
|
|
|
|
Cyrilix wrote: I'm compiling in Visual Studio 2003
I definitely recommend moving to at least VS 2005 (VC 8) any way you can,
as soon as you can, before investing a lot of time in code that is incompatible
with newer/future C++ compilers.
With VC8+, you get the actual C++/CLI language instead of the Managed Extensions
you are using with VC7, which aren't supported anymore (there's a compiler switch
to allow it...for now).
The Managed Extensions for C++ syntax is deprecated.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|