Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Should RGBA have got 4 arguments constructor?
Re: Should RGBA have got 4 arguments constructor? [message #43395 is a reply to message #43179] Thu, 24 July 2014 22:32 Go to previous messageGo to previous message
Klugier is currently offline  Klugier
Messages: 1099
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Mirek,

We can easily implement RGBA constructor in C++11 branch... This standard changes a little bit POD rules. Now we can define constructor, but firstly we need to tell compiler that default constructor exists. I enclose demonstrative code:

#include <Core/Core.h>

#include <type_traits>

using namespace Upp;

namespace UppCpp11 {
struct RGBA {
	RGBA() = default;
	RGBA(byte r, byte g, byte b, byte a) {
		this->r = r;
		this->g = g;
		this->b = b;
		this->a = a;
	}
	
	byte b, g, r, a;
};

struct NotPodRGBA {
	NotPodRGBA(byte r, byte g, byte b, byte a) {
		this->r = r;
		this->g = g;
		this->b = b;
		this->a = a;
	}
	
	byte b, g, r, a;
};
}

CONSOLE_APP_MAIN
{
	UppCpp11::RGBA color(255, 255, 255, 255);
	Cout() << "Is RGBA POD? " << (std::is_pod<UppCpp11::RGBA>::value ? "True" : "False") << "!\n";
	Cout() << "Is NotPodRGBA POD? " << (std::is_pod<UppCpp11::NotPodRGBA>::value ? "True" : "False") << "!\n";
}


Result:
Is RGBA POD? True!
Is NotPodRGBA POD? False!


More information you can find on: http://stackoverflow.com/questions/4178175/what-are-aggregat es-and-pods-and-how-why-are-they-special/7189821#7189821 - second answer.

P.S.
Tested with g++ 4.8 using std=c++11 flag.

Sincerely,
Klugier


U++ - one framework to rule them all.

[Updated on: Thu, 24 July 2014 22:35]

Report message to a moderator

 
Read Message icon5.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Drawing performance issue
Next Topic: Painter and viewports
Goto Forum:
  


Current Time: Tue May 13 01:37:58 CEST 2025

Total time taken to generate the page: 0.01151 seconds