Search Results

Search found 3389 results on 136 pages for 'const'.

Page 9/136 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Graphics module: Am I going the right way?

    - by Paul
    I'm trying to write the graphics module of my engine. That is, this part of the code only provides an interface through which to load images, fonts, etc and draw them on the screen. It is also a wrapper for the library I'm using (SDL in this case). Here are the interfaces for my Image, Font and GraphicsRenderer classes. Please tell me if I'm going the right way. Image class Image { public: Image(); Image(const Image& other); Image(const char* file); ~Image(); bool load(const char* file); void free(); bool isLoaded() const; Image& operator=(const Image& other); private: friend class GraphicsRenderer; void* data_; }; Font class Font { public: Font(); Font(const Font& other); Font(const char* file, int ptsize); ~Font(); void load(const char* file, int ptsize); void free(); bool isLoaded() const; Font& operator=(const Font& other); private: friend class GraphicsRenderer; void* data_; }; GrapphicsRenderer class GraphicsRenderer { public: static GraphicsRenderer* Instance(); void blitImage(const Image& img, int x, int y); void blitText(const char* string, const Font& font, int x, int y); void render(); protected: GraphicsRenderer(); GraphicsRenderer(const GraphicsRenderer& other); GraphicsRenderer& operator=(const GraphicsRenderer& other); ~GraphicsRenderer(); private: void* screen_; bool initialize(); void finalize(); };

    Read the article

  • Odd behavior when recursively building a return type for variadic functions

    - by Dennis Zickefoose
    This is probably going to be a really simple explanation, but I'm going to give as much backstory as possible in case I'm wrong. Advanced apologies for being so verbose. I'm using gcc4.5, and I realize the c++0x support is still somewhat experimental, but I'm going to act on the assumption that there's a non-bug related reason for the behavior I'm seeing. I'm experimenting with variadic function templates. The end goal was to build a cons-list out of std::pair. It wasn't meant to be a custom type, just a string of pair objects. The function that constructs the list would have to be in some way recursive, with the ultimate return value being dependent on the result of the recursive calls. As an added twist, successive parameters are added together before being inserted into the list. So if I pass [1, 2, 3, 4, 5, 6] the end result should be {1+2, {3+4, 5+6}}. My initial attempt was fairly naive. A function, Build, with two overloads. One took two identical parameters and simply returned their sum. The other took two parameters and a parameter pack. The return value was a pair consisting of the sum of the two set parameters, and the recursive call. In retrospect, this was obviously a flawed strategy, because the function isn't declared when I try to figure out its return type, so it has no choice but to resolve to the non-recursive version. That I understand. Where I got confused was the second iteration. I decided to make those functions static members of a template class. The function calls themselves are not parameterized, but instead the entire class is. My assumption was that when the recursive function attempts to generate its return type, it would instantiate a whole new version of the structure with its own static function, and everything would work itself out. The result was: "error: no matching function for call to BuildStruct<double, double, char, char>::Go(const char&, const char&)" The offending code: static auto Go(const Type& t0, const Type& t1, const Types&... rest) -> std::pair<Type, decltype(BuildStruct<Types...>::Go(rest...))> My confusion comes from the fact that the parameters to BuildStruct should always be the same types as the arguments sent to BuildStruct::Go, but in the error code Go is missing the initial two double parameters. What am I missing here? If my initial assumption about how the static functions would be chosen was incorrect, why is it trying to call the wrong function rather than just not finding a function at all? It seems to just be mixing types willy-nilly, and I just can't come up with an explanation as to why. If I add additional parameters to the initial call, it always burrows down to that last step before failing, so presumably the recursion itself is at least partially working. This is in direct contrast to the initial attempt, which always failed to find a function call right away. Ultimately, I've gotten past the problem, with a fairly elegant solution that hardly resembles either of the first two attempts. So I know how to do what I want to do. I'm looking for an explanation for the failure I saw. Full code to follow since I'm sure my verbal description was insufficient. First some boilerplate, if you feel compelled to execute the code and see it for yourself. Then the initial attempt, which failed reasonably, then the second attempt, which did not. #include <iostream> using std::cout; using std::endl; #include <utility> template<typename T1, typename T2> std::ostream& operator <<(std::ostream& str, const std::pair<T1, T2>& p) { return str << "[" << p.first << ", " << p.second << "]"; } //Insert code here int main() { Execute(5, 6, 4.3, 2.2, 'c', 'd'); Execute(5, 6, 4.3, 2.2); Execute(5, 6); return 0; } Non-struct solution: template<typename Type> Type BuildFunction(const Type& t0, const Type& t1) { return t0 + t1; } template<typename Type, typename... Rest> auto BuildFunction(const Type& t0, const Type& t1, const Rest&... rest) -> std::pair<Type, decltype(BuildFunction(rest...))> { return std::pair<Type, decltype(BuildFunction(rest...))> (t0 + t1, BuildFunction(rest...)); } template<typename... Types> void Execute(const Types&... t) { cout << BuildFunction(t...) << endl; } Resulting errors: test.cpp: In function 'void Execute(const Types& ...) [with Types = {int, int, double, double, char, char}]': test.cpp:33:35: instantiated from here test.cpp:28:3: error: no matching function for call to 'BuildFunction(const int&, const int&, const double&, const double&, const char&, const char&)' Struct solution: template<typename... Types> struct BuildStruct; template<typename Type> struct BuildStruct<Type, Type> { static Type Go(const Type& t0, const Type& t1) { return t0 + t1; } }; template<typename Type, typename... Types> struct BuildStruct<Type, Type, Types...> { static auto Go(const Type& t0, const Type& t1, const Types&... rest) -> std::pair<Type, decltype(BuildStruct<Types...>::Go(rest...))> { return std::pair<Type, decltype(BuildStruct<Types...>::Go(rest...))> (t0 + t1, BuildStruct<Types...>::Go(rest...)); } }; template<typename... Types> void Execute(const Types&... t) { cout << BuildStruct<Types...>::Go(t...) << endl; } Resulting errors: test.cpp: In instantiation of 'BuildStruct<int, int, double, double, char, char>': test.cpp:33:3: instantiated from 'void Execute(const Types& ...) [with Types = {int, int, double, double, char, char}]' test.cpp:38:41: instantiated from here test.cpp:24:15: error: no matching function for call to 'BuildStruct<double, double, char, char>::Go(const char&, const char&)' test.cpp:24:15: note: candidate is: static std::pair<Type, decltype (BuildStruct<Types ...>::Go(BuildStruct<Type, Type, Types ...>::Go::rest ...))> BuildStruct<Type, Type, Types ...>::Go(const Type&, const Type&, const Types& ...) [with Type = double, Types = {char, char}, decltype (BuildStruct<Types ...>::Go(BuildStruct<Type, Type, Types ...>::Go::rest ...)) = char] test.cpp: In function 'void Execute(const Types& ...) [with Types = {int, int, double, double, char, char}]': test.cpp:38:41: instantiated from here test.cpp:33:3: error: 'Go' is not a member of 'BuildStruct<int, int, double, double, char, char>'

    Read the article

  • Temporary non-const istream reference in constructor (C++)

    - by Christopher Bruns
    It seems that a constructor that takes a non-const reference to an istream cannot be constructed with a temporary value in C++. #include <iostream> #include <sstream> using namespace std; class Bar { public: explicit Bar(std::istream& is) {} }; int main() { istringstream stream1("bar1"); Bar bar1(stream1); // OK on all platforms // compile error on linux, Mac gcc; OK on Windows MSVC Bar bar2(istringstream("bar2")); return 0; } This compiles fine with MSVC, but not with gcc. Using gcc I get a compile error: g++ test.cpp -o test test.cpp: In function ‘int main()’: test.cpp:18: error: no matching function for call to ‘Bar::Bar(std::istringstream)’ test.cpp:9: note: candidates are: Bar::Bar(std::istream&) test.cpp:7: note: Bar::Bar(const Bar&) Is there something philosophically wrong with the second way (bar2) of constructing a Bar object? It looks nicer to me, and does not require that stream1 variable that is only needed for a moment.

    Read the article

  • Return a Const Char* by reading an @property NSString in separate class

    - by Andrew
    I'm probably being an idiot here, but I cannot for the life of me find the answer that I'm looking for. I have an array of CalEvents returned from a CalendarStore query, and for other reasons I am finding the first location of any upcoming event for today that is not an all-day or multi-day event. +(const char*) suggestFirstiCalLocation{ CalCalendarStore *store = [CalCalendarStore defaultCalendarStore]; NSPredicate *allEventsPredicate = [CalCalendarStore eventPredicateWithStartDate:[NSDate date] endDate:[[NSDate date] initWithTimeIntervalSinceNow:3600] calendars:[store calendars]]; NSArray *currentEventCalendarArray = [store eventsWithPredicate:allEventsPredicate]; for (int i = 0; i< [currentEventCalendarArray count]; i++){ if (![[currentEventCalendarArray objectAtIndex:i] isAllDay]){ //Now that other events are cleared, check for multi-day NSDate *startOnDate = [[currentEventCalendarArray objectAtIndex:i] startDate]; NSDate *endOnDate = [[currentEventCalendarArray objectAtIndex:i] endDate]; if ([endOnDate timeIntervalSinceDate:startOnDate ] < 86400.0){ NSString * iCalLocation = [[currentEventCalendarArray objectAtIndex:i] location]; return [iCalLocation UTF8String]; } } } return ""; } For other reasons, I am returning a const char with the value of the location that is found. However, I cannot seem to return "iCalLocation" at all. The compiler fails on the line where I am initializing the "iCalLocation" variable: "Cannot convert to pointer type" Being frank: I am new to Objective-C, and I am still trying to figure points, properties, and such out.

    Read the article

  • C++ constant reference lifetime

    - by aaa
    hello I have code that looks like this: class T {}; class container { const T &first, T &second; container(const T&first, const T & second); }; class adapter : T {}; container(adapter(), adapter()); I thought lifetime of constant reference would be lifetime of container. However, it appears otherwise, adapter object is destroyed after container is created, leading dangling reference. What is the correct lifetime? how to correctly implement binding temporary object to class member reference? Thanks

    Read the article

  • Static functions vs const functions

    - by baash05
    I'm looking at a member function int funct(int x) const; And I'm wondering if static int funct(int x); would be better. If a member function doesn't use any of the member variables should it be static. Are there any things that would discourage this?

    Read the article

  • Why is casting Derived** to Base*const* forbidden ?

    - by smerlin
    After reading this question, i saw the answer by Naveen containing a link to this page, which basically says, that casting from Derived** to Base** is forbidden since could change a pointer to an pointer to a Derived1 object point to a pointer to a Derived2 object (like: *derived1PtrPtr=derived2Ptr). OK, i understand this is evil ... But when casting Derived** to Base*const* this is not even possible, so whats the reason that this is not allowed anyway ?

    Read the article

  • error C2440: 'initializing' : cannot convert from 'const wchar_t [9]' to 'LPCSTR'

    - by numerical25
    When I add the following to my code. // Define the input layout D3D10_INPUT_ELEMENT_DESC layout[] = { { L"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = sizeof(layout)/sizeof(layout[0]); I get the following error 1>c:\users\numerical25\desktop\intro todirectx\msdntutorials\tutorial0\tutorial\tutorial\main.cpp(43) : error C2440: 'initializing' : cannot convert from 'const wchar_t [9]' to 'LPCSTR' The error points straight to that line of code. if i remove the code, everything compiles correctly.

    Read the article

  • ActionScript Reading Static Const Array

    - by TheDarkIn1978
    how can i evaluate weather my test array is equal to my static constant DEFAULT_ARRAY? shouldn't my output be returning true? public class myClass extends Sprite { private static const DEFAULT_ARRAY:Array = new Array(1, 2, 3); public function myClass() { var test:Array = new Array(1, 2, 3); trace (test == DEFAULT_ARRAY); } //traces false

    Read the article

  • g++ creates several symbols of a const ?

    - by nissen
    In one of my header (C++) files I changed #define TIMEOUT 10 to the more(?) C++ way: const int TIMEOUT = 10; It seems however, g++(v 4.4.3) now includes this symbol several times in the binary. $ nm -C build/ipd/ipd |head 08050420 T ToUnixTime 08050470 T ParseTime 080504c0 T ParseISOTime 080518e4 r TIMEOUT 080518ec r TIMEOUT 080518f4 r TIMEOUT 080518fc r TIMEOUT 080503e0 T HandleMessage How come ?

    Read the article

  • ActionScript Defining a Static Constant Array

    - by TheDarkIn1978
    is it not possible to define a static const array? i would like to have an optional parameter to a function that is an array of colors, private static const DEFAULT_COLORS:Array = new Array(0x000000, 0xFFFFFF); public function myConstructor(colorsArray:Array = DEFAULT_COLORS) { } i know i can use ...args but i actually wanting to supply the constructor with 2 separate arrays as option arguments.

    Read the article

  • error CS0133: Assigning the result of a function to a const in C#.net

    - by Greg
    Trying to tidy up scope and avoid possible multiple calls to RegisterWindowMessage. Currently have a class used once with the following member [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern int RegisterWindowMessage(string lpString); private int m_message = RegisterWindowMessage("MY_MSG"); As we only have one instance this seems ok, but think it would be more tidy to use. With my basic C# understanding this should call RegisterWindowMessage and assign the result to int and not allow it to change. private const int message = RegisterWindowMessage("MY_MSG"); however attempting to do so leads to a error CS0133: The expression being assigned to 'someclass.messageEvent' must be constant so now I'm confused, does this mean the function was being assigned and called each time m_message was used previously, is there something else missing?

    Read the article

  • Avoiding improper std::string initialization with NULL const char* using g++

    - by pachanga
    A there any g++ options which can detect improper initialization of std::string with NULL const char*? I was in the process of turning some int fields into std::string ones, i.e: struct Foo { int id; Foo() : id(0) {} }; ...turned into: struct Foo { std::string id; Foo() : id(0) {} //oooops! }; I completely overlooked bad 'id' initialization with 0 and g++ gave me no warnings at all. This error was detected in the run time(std::string constructor threw an exception) but I'd really like to detect such stuff in the compile time. Is there any way?

    Read the article

  • C++ Ambiguous call to Overloaded Function (const variety)

    - by Joe
    After researching this online, I've only found solutions that don't apply to my problem, so please bear with me. Code snippet: typedef my_map_t<int const *, float> _test; my_map_t::const_iterator not_found = my_map_t::end(); if (_test.find(&iKeyValue) == not_found) { _test[iKeyValue] = 4 + 5; // not the actual code, but here for simplicity } The compiler complains that there's an ambiguous call to my_map_t::end(). This makes sense, because the only difference is the return type. Output: error C2668: 'std::_Tree<_Traits>::end' : ambiguous call to overloaded function Normally you can disambiguate the call by casting the parameters, but end() has no parameters. Any ideas?

    Read the article

  • Unreachable code detected by using const variables

    - by Anton Roth
    I have following code: private const FlyCapture2Managed.PixelFormat f7PF = FlyCapture2Managed.PixelFormat.PixelFormatMono16; public PGRCamera(ExamForm input, bool red, int flags, int drawWidth, int drawHeight) { if (f7PF == FlyCapture2Managed.PixelFormat.PixelFormatMono8) { bpp = 8; // unreachable warning } else if (f7PF == FlyCapture2Managed.PixelFormat.PixelFormatMono16){ bpp = 16; } else { MessageBox.Show("Camera misconfigured"); // unreachable warning } } I understand that this code is unreachable, but I don't want that message to appear, since it's a configuration on compilation which just needs a change in the constant to test different settings, and the bits per pixel (bpp) change depending on the pixel format. Is there a good way to have just one variable being constant, deriving the other from it, but not resulting in an unreachable code warning? Note that I need both values, on start of the camera it needs to be configured to the proper Pixel Format, and my image understanding code needs to know how many bits the image is in. So, is there a good workaround, or do I just live with this warning?

    Read the article

  • error: 'QTabWidget::QTabWidget(const QTabWidget&)' is private

    - by Mahdi_Nine
    I develop a program and I have 10 backups of it. I added some lines to it and when I compiled the project and now it has the following error: C:\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtWidgets\qtabwidget.h:173: error: 'QTabWidget::QTabWidget(const QTabWidget&)' is private the error is from * line namespace Ui { class ContentControl; } class ContentControl : public QTabWidget // * from this line { Q_OBJECT public: . . . } All backups have this error now. Any idea why? I re-installed Qt but the problem is still present.

    Read the article

  • converting an array of characters to a const gchar*

    - by Mark Roberts
    I've got an array of characters which contains a string: char buf[MAXBUFLEN]; buf[0] = 'f'; buf[1] = 'o'; buf[2] = 'o'; buf[3] = '\0'; I'm looking to pass this string as an argument to the gtk_text_buffer_insert function in order to insert it into a GtkTextBuffer. What I can't figure out is how to convert it to a const gchar *, which is what gtk_text_buffer_insert expects as its third argument. Can anybody help me out?

    Read the article

  • How to pass a const unsigned char * from c++ to c#

    - by tzup
    So I have a function in unmanaged c++ that gets called when some text happens to have "arrived": #using <MyParser.dll> ... void dump_body(const unsigned char *Body, int BodyLen) { // Need to pass the body to DumpBody, but as what type? ... lMyParser::Parser::DumpBody(???); } DumpBody is a function defined in a C# DLL that should take one parameter of type? Body holds an array of characters (text) of length BodyLen. There's obviously some marshalling to be done here but I have no idea how. Please help.

    Read the article

  • Windows C++: LPCTSTR vs const TCHAR

    - by mrl33t
    In my application i'm declaring a string variable near the top of my code to define the name of my window class which I use in my calls to RegisterClassEx, CreateWindowEx etc.. Now, I know that an LPCTSTR is a typedef and will eventually follow down to a TCHAR (well a CHAR or WCHAR depending on whether UNICODE is defined), but I was wondering whether it would be better to use this: static LPCTSTR szWindowClass = TEXT("MyApp"); Or this: static const TCHAR szWindowClass[] = TEXT("MyApp"); I personally prefer the use of the LPCTSTR as coming from a JavaScript, PHP, C# background I never really considered declaring a string as an array of chars. But are there actually any advantages of using one over the other, or does it in fact not even make a difference as to which one I choose? Thank you, in advanced, for your answers.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >