|
No, that wouldn't make sense, but it also wouldn't compile. I was under the impression that templates are compiled on a per template-parameter basis... ie, for each distinct set of template parameters, there exists independent assembly at distinct memory addresses. I interpret this as meaning, "As long as a template is syntactically correct, it will be compiled once for each distinct set of template parameters". Therefore, I would expect someone who called my code with class "FooBar" as the template parameter to get an error notifying him/her of an unknown or invalid type, whereas someone compiling with int would work just fine.
As an aside, just because a piece of C++ code can be used in a way that doesn't make sense doesn't mean it is invalid code. The compiler doesn't complain at all if I call numeric_limits<FooBar>::digits, which clearly also doesn't make sense. Sometimes when performing design by contract, verifying that the user abides by the contract is far too expensive to be practical. Most C++ code cannot be written to be idiot-proof.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
what compiler was used compile a classes in c++
if any subract compiler for classes is there... if there means what about c++ compiler done.....
Best Regard's
Mathy's
|
|
|
|
|
|
Depends on what platform you are targeting and what platform you are using to develop your programs. Please offer more details on these.
|
|
|
|
|
using only windows platform.....
if am using classes in C programming.... how to compile a classes in C compiler. Its possiable.
Best Regard's
Mathy's
|
|
|
|
|
C++ compilers are a lot more complicated than C compilers. I am not aware of a C compiler that can compile C++ classes. Why don't you use a C++ compiler? Other replies to your post already gave you suggestions on which compilers you can use to do that.
|
|
|
|
|
All C++ compilers compile (syntactly correct) classes.
As it stands your question make no sense to me.
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]
|
|
|
|
|
Could someone knowledgeable about usage of DLL in VC 6.0 give me a hand. I need a short description about the organization of the files in the project.
I checked this site and found some helpful articles but I am still not sure about how to do this.
I am doing a main project with dependent DLL.
The wizard created a DLL with samples, however, I am confused how to integrate this to the main project.
I have a basic understanding about this macro __declspec(dllexport).
However , there are lib and linker "options" __declspec(lib, "xx.lib") and __declspec(link, "xx.lib") which I do not understand.
These options accomplish the same as VC Project Options, right?
Also, the #include "library.h" is now in debug directory. I assume that I need a #ifdebug directive somewhere to keep the reference correct in release.
Do I still need to register the DLL with windows (regsvr32) ??
Thanks for reading. Appreciate your help.
Cheers Vaclav
This is VC 6.0 DLL wizard generated stuff
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the OPENHRLIB_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// OPENHRLIB_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef OPENHRLIB_EXPORTS
#define OPENHRLIB_API __declspec(dllexport)
#else
#define OPENHRLIB_API __declspec(dllimport)
#endif
|
|
|
|
|
Well, that is rather a lot of questions to answer, however, I'll try.
Vaclav_Sal wrote: I have a basic understanding about this macro __declspec(dllexport).
Knowledge of this is less important than understanding how a library (lib or dll) is linked to an executable. If you read the MSDN literature it should make this clearer.
Vaclav_Sal wrote: However , there are lib and linker "options" __declspec(lib, "xx.lib") and __declspec(link, "xx.lib") which I do not understand.
The lib processor collects a set of object modules and builds a static (lib) or dynamic (dll) library. Generaly speaking Visual Studio or VC will set the correct options when you create the project. The linker options should be set when you select the lib file into your linker settings in the project options.
Vaclav_Sal wrote: Also, the #include "library.h" is now in debug directory. I assume that I need a #ifdebug directive somewhere to keep the reference correct in release.
I'm not sure what you mean here, but I presume that this include should be added to your project whether debug or not, so you probably do not need any #ifdef .
Vaclav_Sal wrote: Do I still need to register the DLL with windows (regsvr32) ?
I'm not sure about this, I just copy the dll to the Windows/System32 directory and my apps tend to work fine.
MVP 2010 - are they mad?
|
|
|
|
|
I have a template that is to be used with numeric binary types, and takes the following form:
template<typename T>
inline T foo(T other) {
if (std::numeric_limits<T>::is_integer) {
T rval(5);
rval |= other;
return rval;
} else {
return 5 * other;
}
} However, as noted in the comment, I get an error when calling the function with T == double. Is there some way to have such a method? I know two approaches that I could use, so I listed them with the associated reasons why I would like to not have to implement them.
Opt 1. Create template specializations for type float, double, and long double. The downside is that this prevents my method from being used in the future when/if the floating point types half (16-bits) or quad (128-bits) are implemented.
Opt 2. Create two different methods, fooInt and fooFloat, and force the user to notify me of the type being used. The only downside here is namespace clutter, so if there isn't some way of implementing foo as I have written it, this is the option I will choose.
Thanks for any assistance,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
You have a problem between compile time checks and execution time checks. If you set T as double then the compiler will, correctly, give the Error C2296, even though your execution time code tries to check (incorrectly) whether the input is an integer; see here[^]. It is probably better to rethink what you are trying to do as the statement rval |= other; makes little sense whatever type T is.
MVP 2010 - are they mad?
|
|
|
|
|
Thank you for your response. Yes, I understand why I am getting the error, as well as the fact that my checks are performed at runtime. My question is, is there some way to accomplish this without having to create a template specialization for every integer and floating point type? It seems absurd that there isn't some compile-time guard that I could use to perform the same logic, but I couldn't think of one specifically. Unless I hear any ideas on how to better accomplish this, I am planning to have one method for floating types and another for integer types. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
The issue to resolve, as I stated in my previous message, is the use of the |= operator. This makes no sense on a float or double operand and is thus rejected. If you really need this operator for some reason then you should cast the operand to an appropriate non-numeric type such as DWORD .
MVP 2010 - are they mad?
|
|
|
|
|
OK... I must not be communicating clearly, so here is how I am currently interpreting your answers:
"There is no way to put a compile-time (ie, using the preprocessor) guard on a block of statements based on the type of a template parameter. If you want to execute code within a template for types with differing interfaces, you must either create specialized templates for each type, create multiple methods with unique signatures, or typecast the input to the appropriate type for each applicable section of code. Any of these methods will work, and there is no other way to accomplish the same thing."
Did I interpret your answers correctly, or is something above not true? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: Did I interpret your answers correctly?
Well almost. All I am saying is that if you are using a template that specifies its type as float or double you must ensure that the following code does not violate any of the rules concerning that type. In your code you are using the |= operator on a value, which really has no meaning for numerics, particularly floating point numbers. All you need to do within your template code is use acceptable operators to manipulate your data, or cast the items to a 'logical' type; for example any of the mathematical operators (+ - * /) should work fine regardless of the type of the numbers.
MVP 2010 - are they mad?
|
|
|
|
|
I'm having the same problem as Jeff.
Your answer that he is using the wrong operator misses the point.
I, for example, am trying to use the shift operators (<< or >>) in a numeric conversion.
The template also needs to take floats, and although I've used boost::is_integral to ensure that floats are not shifted, the compiler cannot see this runtime decision.
|
|
|
|
|
Ken Moynihan wrote: Your answer that he is using the wrong operator misses the point.
On the contrary, that is the point. If you wish to compile source code then that source must follow the rules of the language. If, at run time, you wish to overrirde or otherwise work around those rules by casting then you are free to do so.
It's time for a new signature.
|
|
|
|
|
I think communication has broken down here.
Thank you for taking the time to reply anyway.
|
|
|
|
|
kmoy007 wrote: I think communication has broken down here.
Obviously! Who are you and why are you responding?
It's time for a new signature.
|
|
|
|
|
Hi,
My application is using GDI+ to handle image as a background. It works OK under Windows XP. I found recently that it display very slow under Windows 7.
Gdiplus::Graphics gr(dc);
gr.SetPageUnit(Gdiplus::UnitPixel);
gr.DrawImage(pBmp, x1, y1, abs(x2-x1), abs(y2-y1));
What kind problem it could be? How can I solve it?
Thank you very much,
|
|
|
|
|
You might want to try updating your video board driver. Don't know for sure if it'll fix it, but this sounds like a typical driver issue.
L u n a t i c F r i n g e
|
|
|
|
|
Hi,
I replaced video card and its driver. It did not improve any. There might something wrong with Windows 7.
Damn Windwos 7,
Thanks your reply.
|
|
|
|
|
CODEPC wrote: Damn Windwos 7
L u n a t i c F r i n g e
|
|
|
|
|
Hi,
Is there a way to close a document without closing the application?
What I mean by this using a menu option, e.g. File -> Close, to invoke a file save if need be, and then clearing the view, but not closing the application?
Obviously I can write a function that will do this for me, but is there a standard CDocument member that will do this for me?
TIA
Tony
|
|
|
|
|
I think you should override the OnCloseDocument method,...Well,...Good luck!
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]
|
|
|
|