- Parsing of types which are described in more than one word - 1 Update
- C++ Constructor : silent amiguity - 2 Updates
- [Modération JNTP] Annulation de <pt9nqg$l56$7@dont-email.me> - 2 Updates
- "The Internet Has a Huge C/C++ Problem and Developers Don't Want to Deal With It" - 3 Updates
- Using port 465 (TLS) instead of 25 SMTP (PlainText). - 1 Update
- Why do we need Q#? - 8 Updates
- Learn Quantum Computing with the Quantum Katas - 1 Update
- Writing a Quantum Program - 1 Update
- Using #define in the construction of an array - 1 Update
- int8_t and char - 2 Updates
- About my next software projects... - 1 Update
- Undefined Behaviour - 1 Update
- Longest word in a dictionary problem -- which container - 1 Update
Paul <pepstein5@gmail.com>: Nov 17 02:55AM -0800 Using a recent version of gcc, the below code (at end of post) doesn't compile. Presumably, this is because "unsigned int" is interpreted as "unsigned int int" which, I agree, does not make sense. It seems to be a precedence problem. std::cout << ( (unsigned int)(230)); works fine. Presumably a C++ expert would know that the below code doesn't compile without needing to try it. Why does the compiler not recognise unsigned int as the type "unsigned" in the below context? Thanks, Paul #include<iostream> int main() { std::cout << (unsigned int(230)); } |
m.labanowicz@gmail.com: Nov 17 10:49AM -0800 Hi, How to force gcc to complain about ambiguity. Following there is example: --{beg:main.cpp}--------------------------------- #include <iostream> class A { public: A() : x(new int) { *x = 0; } virtual ~A() { delete x; } virtual void run() { std::cout << (void *)this << ":" << *x << std::endl; } private: int * x; }; class B : public A { public: B(A & a) : a(a) { } virtual void run() { a.run(); } private: A & a; }; int main(void) { A a; A other; B b(other); a.run(); b.run(); A * ptrA = new B(a); #if 1 // wrong A * ptrB = new B(b); // <------ this is the point of issue // simple allocation and copy Memory is executed // instead of defined Constructor #else // good A * ptrB = new B(static_cast<A &>(b));
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment