|
hello i has created a vector and i declared as follow:
struct CharacterCoordinate<br />
{<br />
GLfloat xpos;<br />
GLfloat ypos;<br />
<br />
};<br />
<br />
std::vector< CharacterCoordinate > CharacterPos;<br />
and i call with
void Scene::CreatInitCharacter(int InitAmount)<br />
{<br />
<br />
<br />
srand(time(0)); <br />
<br />
CharacterCoordinate *PtrCreat;<br />
<br />
for(int i=0;i<InitAmount;i++)<br />
{<br />
PtrCreat = new CharacterCoordinate();
CharacterPos.push_back(PtrCreat);<br />
<br />
PtrCreat->xpos = ( ( 1 + rand( ) % 120 ) - 70 );<br />
PtrCreat->xpos = ( ( 1 + rand( ) % 120 ) - 70 );<br />
<br />
<br />
<br />
<br />
<br />
<br />
}<br />
<br />
}<br />
and i have this message error
error C2664: 'push_back' : cannot convert parameter 1 from 'struct CharacterCoordinate *' to 'const struct CharacterCoordinate &'<br />
Reason: cannot convert from 'struct CharacterCoordinate *' to 'const struct CharacterCoordinate'<br />
No constructor could take the source type, or constructor overload resolution was ambiguous<br />
and i want to store in the structur but when i want to store in the vector
|
|
|
|
|
You have defined a vector of struct CharacterCoordinate s, but you are trying to add a pointer to such a structure into the vector. Change the code in CreatInitCharacter to:
CharacterCoordinate Creat;
for(int i=0;i < initAmount; ++i)
{
Creat.xpos = ( ( 1 + rand( ) % 120 ) - 70 );
Creat.ypos = ( ( 1 + rand( ) % 120 ) - 70 );
CharacterPos.push_back(Creat);
}
|
|
|
|
|
When I wanted to read the vector of structur i have error:
<br />
for(int Index=0;Index<CharacterPos.size() ; Index++)<br />
{<br />
glTranslated(CharacterPos[Index]->xpos,CharacterPos[Index]->ypos , 0 );
}
void Scene::CreatInitCharacter(int InitAmount)<br />
{<br />
<br />
<br />
srand(time(0)); <br />
<br />
CharacterCoordinate PtrCreat;<br />
<br />
for(int i=0;i<InitAmount;i++)<br />
{<br />
PtrCreat = new CharacterCoordinate();
<br />
<br />
PtrCreat.xpos = ( ( 1 + rand( ) % 120 ) - 70 );<br />
PtrCreat.ypos = ( ( 1 + rand( ) % 120 ) - 70 );<br />
CharacterPos.push_back(PtrCreat);<br />
<br />
}<br />
<br />
}<br />
i have this error
62) : error C2819: type 'CharacterCoordinate' does not have an overloaded member 'operator ->'<br />
c:\program files\microsoft visual studio\myprojects\essai\mfcopengl\scene.h(21) : see declaration of 'CharacterCoordinate'<br />
(62) : error C2227: left of '->xpos' must point to class/struct/union<br />
(62) : error C2819: type 'CharacterCoordinate' does not have an overloaded member 'operator ->'<br />
(21) : see declaration of 'CharacterCoordinate'<br />
(62) : error C2227: left of '->ypos' must point to class/struct/union<br />
88) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct CharacterCoordinate *' (or there is no acceptable conversion)<br />
|
|
|
|
|
Use CharacterCoordinate[index].xpos and CharacterCoordinate[index].ypos to access the members and get rid of the new . The CharacterPos.push_back() takes care of allocating memory space when necessary. The vector stores actual structs, not pointers to them.
|
|
|
|
|
i make this modification but the error is be here also
(62) : error C2275: 'CharacterCoordinate' : illegal use of this type as an expression<br />
(21) : see declaration of 'CharacterCoordinate'<br />
(62) : error C2228: left of '.xpos' must have class/struct/union type<br />
(62) : error C2275: 'CharacterCoordinate' : illegal use of this type as an expression<br />
(21) : see declaration of 'CharacterCoordinate'<br />
(62) : error C2228: left of '.ypos' must have class/struct/union type<br />
|
|
|
|
|
|
For a module I want to write my own stream class.
Although not identical the following example illustrates what I want to do:
suppose you have a class representing a printer:
class Printer { ...};
I want the user of this class to send data to this class using the << operator, so that any data type/class, for which << is defined on streams, e.g.
Printer myPrinter (printerName);
PrinterStream &printStr = myPrinter.getStream();
printStr << "Hello world" << 123 << std::endl;
So, how can I write my own stream class so that I can intercept the data send to printStr?
I probably need to inherit from some STL stream class, but I don't know where to start. Is this something that can be done easily, or is this almost impossible?
Another alternative (although I don't really like it) is to let my getStream() method to return a stringstream. My class then simply needs a kind of flush method to get the data from the stringstream, send it to the output where I want it and then empty the stringstream. I don't like this alternative because it exposes the fact that's a stringstream to the caller. Also I cannot add my own output manipulators (e.g. to set the font or color) to the stream.
Does anybody know a simple solution, or point me to an article that explains how to write your own stream class?
Thanks in advance.
Enjoy life, this is not a rehearsal !!!
My Articles:
- Implementing a Subject/Observer pattern with templates
- Different ways of writing class factories
- AutoRunner: a template class to automatically run start- and cleanup-code in code blocks
</
|
|
|
|
|
use Subject/Observer pattern ![Poke tongue | ;-P](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_tongue.gif)
|
|
|
|
|
Writing your iostream class is not hard, but it's not trivial either. Basically you have to make CPrinter derive from std::ostream and provide a special std::streambuf class:
class CPrinter: public std::ostream
{
typedef std::ostream super;
CPrinterStreambuf sbuf;
public:
CPrinter():super(&buf){}
...
}; Now, std::ostream handles all the IO via the provided CPrinterStreambuf object, which derives from the virtual base class std::streambuf . Depending on where you want the bytes to be sent, you might consider writing CPrinterStreambuf from scratch or deriving from say std::filebuf or std::stringbuf . Now you can intercept outgoing data by overriding overflow and sync . Here[^] is an example provided by MS that might be useful.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
hello
i create a vector where i store the random number but when i compile it use only the last couple of number that had generated by random.
where is the problem ,is that the vector don't work or it don't store the firsts numbers or it's me who don't well use the vector?????
void foufou::CreateCharacter(int amount) <br />
{ <br />
int randomX =0,randomY =0,randomZ =0; <br />
<br />
foufou *PtrCreat; <br />
<br />
for(int i=0;i<amount;i++) <br />
{ <br />
PtrCreat = new foufou();
VectorOfCharacter.push_back(PtrCreat); <br />
<br />
initPosX = ( ( 1 + rand( ) % 120) - 70 ); <br />
initPosY = ( ( 1 + rand( ) % 120 ) - 70 ); <br />
<br />
<br />
<br />
<br />
NumCharacter++; <br />
} <br />
<br />
} <br />
<br />
<br />
<br />
<br />
<br />
void foufou:rawCharacterOnInitSimulation() <br />
{ <br />
<br />
for(int i=0 ;i<VectorOfCharacter.size() ;i++) <br />
{ <br />
<br />
DrawCreatedCharacter(VectorOfCharacter[i]->initPosX, VectorOfCharacter[i]->initPosY); <br />
<br />
} <br />
<br />
<br />
<br />
} <br />
<br />
|
|
|
|
|
If I understand your code, the line
initPosX = ( ( 1 + rand( ) % 120) - 70 ); should be
PtrCreat->initPosX = ( ( 1 + rand( ) % 120) - 70 ); (and the same for the next line).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
i have a listview with LVS_EX_FULLROWSELECT style.I use AddItem to add an icon into the view.When i run the app,everything appears to be good.However,when i click the row to select it,the texts in the row are highlighted but icons DISAPPEARED!I tried several other ways (InsertItem or SendMessage),but these made no difference.I wonder if there is any possibility to insert icons to a listview?!
BTW:i want icons inserted in both headers and items,but the background colors of them are different,but one ImageList can have only one bkcolor(maybe more,i'm not sure).so is there any solution to this problem?
modified 1-May-21 21:01pm.
|
|
|
|
|
I used ATL create a Dll project,
I want get current DLL directory, I used ::GetCurrentDirectory() API,
but I only get the EXE 's current path.
I want get Dll's directory
what can I do ?
I believe I can touch the sky
|
|
|
|
|
GetModuleFileName will return the full path of the module you specify. If you give it NULL for the hInstance, then it will return the path of the main executable.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks you get me this help
I used GetModuleFileName() by your's suggest.
It's good
I believe I can touch the sky
|
|
|
|
|
|
I know CFileDialog class is MFC Class,
But I want used this class in WTL project.
I include afxdlgs.h at my project but is error
"WINDOWS.H already included. MFC apps must not #include <windows.h>"
I want know have similar calss in WTL ?
I believe I can touch the sky
|
|
|
|
|
I haved find similar class - CFileDialog in atldlgs.h
Thanks myself;P
I believe I can touch the sky
|
|
|
|
|
Hey,
I am trying to use CString in my ATL IE Toolbar. I had some compiler errors and then read an article that said I had to include atlstr.h. I have VC 6.0 but cannot find atlstr.h, can anyone show me where I can get it or send it to me?
Thanks in advance.
|
|
|
|
|
Upgrade to VC7. It isn't available in VC6.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
Michael Dunn wrote:
VC 7 has a shared CString class between ATL and MFC. Since you're using 6, you should use WTL, which has its own CString.
How do I use WTL when its programmed in ATL? Or are they almost the same? Sorry, I don't really know much about either of the languages.
|
|
|
|
|
|
Hey Guys,
I'm trying to port a plain WIN32 dll over to another system which uses ATL to implement the interface. I know nothing about ATL but I've sort of got it working aside from the fact I can't figure out how to get the HINSTANCE of my DLL.
The DLLmain does the following
CComModule _Module;
BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_My_Plugin, CMyPlugin)
END_OBJECT_MAP()
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID )
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_Module.Init(ObjectMap, hInstance);
DisableThreadLibraryCalls(hInstance);
}
else if (dwReason == DLL_PROCESS_DETACH)
_Module.Term();
return TRUE;
}
I can see the _Module gets the HINSTANCE here but how do I get to it from the CMyPlugin class?
Cheers
James
|
|
|
|