|
Hi
I want to use vector to save following struct. It it possible?
template <class t="">
struct Cell
{
T Val;
};
vector <<cell>> vname ?????
What is the best solution for it?
Thanks,
modified on Sunday, March 1, 2009 1:49 PM
|
|
|
|
|
For example:
template <typename T>
struct Cell
{
T Val;
};
#define CELL_TEMPLATE(type) Cell<type>
std::vector<CELL_TEMPLATE(int)> my_cell_vector;
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thank you very much for your reply. I want to use one vector to save different data type of data. How can I do it?
Best,
|
|
|
|
|
What exactly do you mean by "save"?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
like following:
Cell<int> typeint;
typeint.Val = 1;
recVec.push_back (typeint);
Cell<float> typefloat;
typefloat.Val = (float) 1.111;
recVec.push_back (typefloat);
|
|
|
|
|
Well, if the structure isn't too complex, you could simply use a union and some way to signal what type your struct is actually holding. Something like:
#define STRUCT_TYPE_FLOAT 1
#define STRUCT_TYPE_DOUBLE 2
#define STRUCT_TYPE_INT 3
...
struct Cell
{
public:
short typeFlag;
union {
float valFloat;
double valDouble;
int valInt;
...
};
};
...
std::vector<Cell> my_vector;
Cell cell_double;
cell_double.valDouble = 1.23;
cell_double.typeFlag = STRUCT_TYPE_DOUBLE;
my_vector.push_back(cell_double);
Cell cell_int;
cell_int.valInt = 123;
cell_int.typeFlag = STRUCT_TYPE_INT;
my_vector.push_back(cell_int);
...
If it's a bit more complex than that then you should rather use pointers, something like this:
class CellBase
{
virtual ~CellBase()
};
template<typename TType>
class Cell: public CellBase
{
...
};
std::vector<cellbase> my_vector;
my_vector.push_back(new Cell<int>(123));
These are far from complete implementations of anything, just "skeletons"...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
|
Hmm, this is strange, i got a new notification of you posting something here, i click the link in the email, it brings me to this page but your message does not appear. I already got one of these once, maybe it is some caching problem, or something i don't yet know about the forums. Anyways, the email itself contains your post so here's an answer to that: in your CCellBase, make the destructor public.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I found the problem. Your solution is perfect.
Best,
|
|
|
|
|
One alternative to Code-o-mat's is to use a 'proper' type-safe variant class like Boost.Variant[^].
typedef boost::variant<int, float> Cell;
std::vector<Cell> cells;
cells.push_back(10);
cells.push_back(12.0);
for (int i=0;i<cells.size();++i)
{
if ( int* pi = boost::get<int>( cells[i] ) )
std::cout << "cells[" << i << "] = " << *pi << std::endl;
else if ( float* pf = boost::get<float>( cells[i] ) )
std::cout << "cells[" << i << "] = " << *pf << std::endl;
}
One design feature of the Boost.Variant is that you need to know what types you want to store when you build the program. Alternatively, you could use a Boost.Any[^], which allows you to store values of any type within it without pre-declaring them.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Can a ellipsis (Variadic) function i.e Func(...) be exported from a DLL.
The function takes variable number of arguments. Can this be exported through a dll?
|
|
|
|
|
Don't see why not - the C run time DLL manages it for printf, sprintf etc which are variadic.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
thanks for the reply, since standard functions are exported so the user defined must also be exported.
|
|
|
|
|
well i want image of any extension to be converted into binary and save it into some file. then read it back to generate image can any one help me plz
|
|
|
|
|
Well, ANY extension (i assume you mean format by extension, since extension is just some characters after the name of the image, which basicly means nothing, i can rename my Whatever.bmp to Whatever.jpg, that won't actually make it a JPEG image...) is a bit broad, but you can use CxImage[^] to load many kinds of formats, then you can create a DIB section using CreateDIBSection[^] and then blit the image onto it. Since CreateDIBSection gives you a pointer at the pixel data, you can do with it whatever you like, like save it as it is. Doing this the other way should be quite straightforward too. Hope that helps.
p.s: Could be that CxImage itself gives you a way to access the "raw" pixel data (or even save it as raw format), am not sure about that, but you can find that out yourself.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
They are already binary. May be you want to encrypt/decrypt them.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
I'm busy following a tutorial where the author uses DUMPBIN to list exports, and OllyDbg to get the assembly code for an exported function. How would I find the functions code in the complete disassemly, given that the export tables RVA's don't correspond to real addresses in the disassembly.
The conceptual Reversing process occurs every time someone looks at someone else’s code. But, it also occurs when a developer looks at his or her own code several days after it was written.
- Elliot Chikofsky, Executive Secretary, IEEE Technical Council on Software Engineering
|
|
|
|
|
I have not used OllyDbg, but using Windbg you can get the unassembly of a function using the u command.
u myexecutable!myfunction
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I can't load a DLL in WindDbg, or if I can, I don't know how to, so I can't try this, but thanks anyway, I've come right with OllyDbg.
The conceptual Reversing process occurs every time someone looks at someone else’s code. But, it also occurs when a developer looks at his or her own code several days after it was written.
- Elliot Chikofsky, Executive Secretary, IEEE Technical Council on Software Engineering
|
|
|
|
|
Doesn't the disassembly include function names? That's the way I tend to read assembly language files, although I'll grant that it's usually (but not always) assembly language generated by the C++ compiler.
If the export is in a DLL, then you can get OllyDbg to a) debug the DLL, and b) call a selected export (by name). The 'call selected export' dialog has a 'Follow in Disassembler' button, which will place the disassembler at the start of that export.
Oh - and if (reading between the lines of some of your other posts) it's a system file you're disassembling, for which you don't have debug symbol information - you can get the debug symbol information from Microsoft[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote:
Doesn't the disassembly include function names?
Not dumpbin's disassembly. I know it's rough, but the author insists on offline analysis, which I agree with, to learn how to read asm code properly. I have IDA Pro Free, which gives me everything, but I don't want everything for the same reason that the author doesn't.
Stuart Dootson wrote: If the export is in a DLL, then you can get OllyDbg to a) debug the DLL, and b) call a selected export (by name). The 'call selected export' dialog has a 'Follow in Disassembler' button, which will place the disassembler at the start of that export.
Cool, thanks!
The conceptual Reversing process occurs every time someone looks at someone else’s code. But, it also occurs when a developer looks at his or her own code several days after it was written.
- Elliot Chikofsky, Executive Secretary, IEEE Technical Council on Software Engineering
|
|
|
|
|
Hey ppl,
I have create a static library project and build it successfully on debug mode and release mode.
Now I have a different project which uses this static library with
#paragma comment (lib, mylib)
When I compile and run my project in debug mode it runs successfully.
When I compile my project in release mode it compiles successfully but wont run. And when I try to run release mode inside Visual Studio it gives me these errors:
Error 1 fatal error C1083: Cannot open source file: '.\XWindow.cpp': No such file or directory c1xx
Error 2 fatal error C1083: Cannot open source file: '.\XTexture.cpp': No such file or directory c1xx
Error 3 fatal error C1083: Cannot open source file: '.\XTextBox.cpp': No such file or directory c1xx
Error 4 fatal error C1083: Cannot open source file: '.\XText.cpp': No such file or directory c1xx
Error 5 fatal error C1083: Cannot open source file: '.\XPen.cpp': No such file or directory c1xx
... list goes on.
These files are included in mylib.lib that's why I used static lib. So why this happens?
One more thing, my library's file size in debug mode is 3.103Kb and in release mode 11.349Kb. I expect it would be more less in relase mode..
Thank you...
|
|
|
|
|
dehseth wrote: When I compile my project in release mode it compiles successfully but wont run. D'Oh! And when I try to run release mode inside Visual Studio it gives me these errors:
What do you mean by "Run" ? These errors are compilation errors, you can't have those when you run your program
dehseth wrote: Error 1 fatal error C1083: Cannot open source file: '.\XWindow.cpp': No such file or directory c1xx
What is "c1xx" at the end ?
Those files which give errors (XWindow.cpp, XTexture.cpp, ...), are they part of your exe or part of your static lib ?
|
|
|
|
|
Application compiles and link successfully:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
But when I double click to generated exe file it crashed So I open visual studio window and press Run button and it gives me these errors I do not get why I get em. There's no c1xx file...
Should I do anything more than putting #pragma comment (lib, "mylib") and include the main header file to make it run on release mode?
|
|
|
|
|
I just delete all Temp files Debug Output files and Release output files. Rebuild library. And rebuil application. Now it runs..
Sometimes we need housekeeping i guess..
|
|
|
|