I have a basic class with a pimpl, with agressive instantiation:
Code:
class MyClassImpl;
class MyClass {
public:
MyClass() : pImpl(new MyClassImpl) {}
[Code] ....
Classic/Standard. However, I do hate having to use pointer semantics for all of my operations. So I thought: If I never ever manipulate the actual pointer itself, why not just keep a reference?
Code:
class MyClassImpl;
class MyClass {
public:
MyClass() : impl(*new MyClassImpl) {}
~MyClass(){delete &impl;}
private:
MyClassImpl& impl;
};
The only downside that I see, is that I can't swap or move, but this particular object is not meant to be swapped or moved.
I'm trying to implement a class hierarchy and a wrapper class with a pointer to the base class. The base class has operator< overloaded and the implementation makes use of virtual functions as some of the logic for sorting is in the derived classes. Unfortunately, when trying to use the base class operator< from the wrapper, I get a "pure virtual method called".
Below code is meant to illustrate my problem. Unfortunately it crashes on me (upon destruction of vec) and I cannot quite see, why. So two questions:
1. spot the error I made in the code below (having lived in Java-land for the last 5 years, I'm sure I just did some stupid error)?
2. How can I implement Wrapper::operator< to use Base::operator<? I know I could write a function and pass it to sort but I'm interessted if there is a way to actually use Base::operator<.
I have encountered a problem I can't see to solve. I want to access a function and can't seem to find the right combination to get me there. Here is what I am looking at:
CFoo1::CFoo2::GetStrDataC(int nRow) const
How do I call the GetStrDataC function from another class?
I am having trouble working with third party dll's, libs and header files. I am trying to call a function.here is the function that is suppose to be called.
Name IN/OUT Description m_environment IN Optional. Possible values are SANDBOX (default) and LIVE. m_strConsumerKey IN OAuth consumer key provided by E*TRADE m_strConsumerSecret IN OAuth consumer secret provided by E*TRADE m_strToken OUT Returned by the function if successful m_strTokenSecret OUT Returned by the function if successful m_strCallback IN Optional; default value is "oob"
vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/
I am getting following error:
vijay13@ubuntu:~/Downloads$ g++ -o test test.cpp -I /home/vijay13/Downloads/OGDF-snapshot/include/ /tmp/ccPE8nCu.o: In function `main': test.cpp:(.text+0x26): undefined reference to `ogdf::Graph::Graph()' ...................... so on
following code that I'm reading out of the book "The C++ Standard Library".
class C { public: explicit C(const std::string & s); // explicit(!) type conversion from strings. ...
[Code].....
Now I understand that they are saying that an explicit conversion isn't allowed but what I don't understand is what explicit conversion would be happening if there was one allowed.
Specifically I don't understand the const C & elem syntax. How does this work since the collection holds strings. What would be the syntax for how this:
const C & elem
gets strings. I was thinking it was a class reference that someone how converts to a constructor function pointer or something but i'm really confused.
This does not allow me to initialize _listRef as something like NULL when it is not applicable.Also, i must change all my constructors and its child class to include an initialization of _listRef!!
What is the alternative? Is pointer the nearest? which of the following should be used?
Code: const QList<QSharedPointer<Data>> * _listRef; or const QList<QSharedPointer<Data>> *const _listRef; or const QSharedPointer<QList<QSharedPointer<Data>>> _listRef; ????
Im trying to reference my array in another function but i keep getting errors.
void player::store() { int menuChoice; int amountChoice = 0; int items[4] = {0,0,0,0}; string inv;
[Code]...
errors
C:UsersChayDesktopDinosaur ArenaMainGame.h|81|error: declaration of 'items' as array of references| C:UsersChayDesktopDinosaur ArenaMainGame.h|81|error: prototype for 'void player::backpack(...)' does not match any in class 'player'| C:UsersChayDesktopDinosaur Arenaplayer.h|24|error: candidate is: void player::backpack()|
Write a complete C++ program with the two alternate functions specified below, each of which simply triples the variable count defined in main. Then compare and contrast the two approaches. These two functions are
a) function tripleByValue that passes a copy of count by value, triples the copy and returns the new value and
b) function tripleByReference that passes count by reference via a reference parameter and triples the original value of count through its alias (i.e., the reference parameter).
Code: #include <iostream> #include <vector> using namespace std;
class A{
[Code]....
I read somewhere, that we can imagine the reference as a pointer to the vector. So, my question is:
Let's assume that instance of class A, named a, was created with new. We call a.getV() to foo and then we call the destructor of a. foo is safe? Is the copy constructor of std::vector called?
I have in my main(), a function that creates my arg object using boost/program_options.hpp i want to pass this object to another function using templates like this:
Code: template <typename Targ> void Count(Targ & arg){ MyObj<string> QueryTab(arg["input-file"].as<string>()); //line number is 352 ... }
However I get an error:
Code: ../include/Filter.hpp: In member function ‘void Count(Targ&)’: ../include/Filter.hpp:352:40: error: expected primary-expression before ‘>’ token ../include/Filter.hpp:352:42: error: expected primary-expression before ‘)’ token ... obviously it does not recognize my intention, what did I do wrong?
Write a function called breakThree that will accept a 3 digit integer and returns each of the numbers individually. This function will take four paramaters. The first parameter is the three digit number to break apart. Parameters 2 through 4 are passed by reference and will be used to return each of the numbers back to main.
You should make sure that the input into the function is a 3-digit number. If it is not a three digit number the breakThree function should simply return false. If it is a three digit number the breakThree function should break the number apart, and store each of the numbers in the parameters passed by reference.
In main you should get the number from input and then output each of the numbers on a separate line.
What not to use global variables cin in breakThree function cout in breakThree function goto statements
#include <iostream> using namespace std; void separate(int a, int b, int c, int d); int main(int argc, const char * argv[]) { int num;
All entities need to be stored in the dynamic memory. I managed to force this by making the constructor private and by adding a static method which dynamically creates an object and returns a pointer. But it is most likely that the user will want to make them dynamically and we still have the following problem.
entity* player = entity::create(); (*player).setPosition(something); (*player).act(); (*player).draw();
You get the point, having to dereference the pointer before each call becomes painful. So I thought about this... Instead of returning a pointer, I can return a reference. Then the code is much cleaner.
{ entity& test = entity::create();
// do stuff... test.act(); // more stuff...
test.destroy(); // deletes the dynamic object }
I put this code between brackets. That's because we must make sure the reference test doesn't exist after destroy is called, because destroy() makes it invalid. This is fully functional and won't cause any problem as long as the user doesn't forget to never call any method on a destroyed entity. But it's evil code. Would you risk it, or is there another way around?
I'm using GCC 4.8.1 and I want to implement a XML parser using TinyXML and port it to AngelScript
Now, it says: reference to 'Column' is ambiguous
I've declared a class called xml_parser and I've added everything of tinyxml as it's public member when I call Column(), and also Row(), it give's this error. what should I do?
When returning an object by reference, only the address of the returned-object is returned, and that way we spare pushing a large object into the stack, and also spare time of pushing and popping large object to/from stack.
But what happens when the object that receiving the returned-object, is not a reference, but a 'regular' object?
How is the content of the returned object copied into the receiving object?
See for example in main, wid vs rwid. (I know in the case the returned-object is just one variable, there's no need to return it by reference, but its for simplifying the code).
class Rectangle { public: Rectangle(int w=0, int h=0);